作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 devexpress grid group row 中画了一个复选框使用下面的代码。
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Drawing;
using DevExpress.Utils.Drawing;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.ViewInfo
using DevExpress.XtraEditors.Drawing;
//...
void gvWorkspaces_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e) {
GridGroupRowPainter groupRowPainter = (GridGroupRowPainter)e.Painter;
GridGroupRowInfo info = (GridGroupRowInfo)e.Info;
groupRowPainter.DrawGroupRowBackground(info);
groupRowPainter.DrawObject(info);
Rectangle checkRect = info.ButtonBounds;
checkRect.X = e.Bounds.Right - checkRect.Width -4;
DrawCheckBox(e.Graphics, checkRect, true);
e.Handled = true;
}
void DrawCheckBox(Graphics graphics, Rectangle r, bool Checked) {
RepositoryItemCheckEdit edit = new RepositoryItemCheckEdit();
CheckEditViewInfo info = (CheckEditViewInfo)edit.CreateViewInfo();
info.EditValue = Checked;
info.Bounds = r;
info.CalcViewInfo(graphics);
CheckEditPainter painter = (CheckEditPainter)edit.CreatePainter();
ControlGraphicsInfoArgs args = new ControlGraphicsInfoArgs(info, new GraphicsCache(graphics), r);
painter.Draw(args);
args.Cache.Dispose();
}
但是,我在访问复选框以勾选和取消勾选时遇到了挑战。
我尝试在 GridView 单击事件中使用 GridHitInfo(如下所示)。但是我没有得到任何可以帮助我访问复选框的信息。
void gvWorkspaces_Click(object sender, EventArgs e) {
GridView view = (GridView)sender;
Point pt = view.GridControl.PointToClient(Control.MousePosition);
GridHitInfo info = view.CalcHitInfo(pt);
}
如有任何帮助,我们将不胜感激。
谢谢
巴兰
最佳答案
您应该使用以下方法:
RepositoryItemCheckEdit edit;
CheckEditViewInfo editInfo;
CheckEditPainter editPainter;
//...
edit = new RepositoryItemCheckEdit();
editInfo = (CheckEditViewInfo)edit.CreateViewInfo();
editPainter = (CheckEditPainter)edit.CreatePainter();
}
Hashtable checkedRows = new Hashtable();
Hashtable editorRects = new Hashtable();
void gvWorkspaces_Click(object sender, EventArgs e) {
GridView view = (GridView)sender;
Point pt = view.GridControl.PointToClient(Control.MousePosition);
GridHitInfo info = view.CalcHitInfo(pt);
if(info.InRow) {
Rectangle editorRect = (Rectangle)editorRects[info.RowHandle];
if(editorRect.Contains(pt)) {
object value = checkedRows[info.RowHandle];
if(value == null)
checkedRows[info.RowHandle] = true;
else checkedRows.Remove(info.RowHandle);
view.GridControl.Invalidate(editorRect);
}
}
}
void gvWorkspaces_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e) {
e.Painter.DrawObject(e.Info);
GridGroupRowInfo info = (GridGroupRowInfo)e.Info;
Rectangle checkRect = info.ButtonBounds;
checkRect.X = e.Bounds.Right - checkRect.Width - 4;
DrawCheckEdit(e.Graphics, checkRect, checkedRows[e.RowHandle] != null);
editorRects[e.RowHandle] = checkRect; // cache rectangle
e.Handled = true;
}
void DrawCheckEdit(Graphics graphics, Rectangle r, bool cheched) {
editInfo.EditValue = cheched;
editInfo.Bounds = r;
editInfo.CalcViewInfo(graphics);
using(GraphicsCache cache = new GraphicsCache(graphics)) {
editPainter.Draw(new ControlGraphicsInfoArgs(editInfo, cache, r));
}
}
关于c# - 组行上的 DevExpress GridHitInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254099/
我在 devexpress grid group row 中画了一个复选框使用下面的代码。 using DevExpress.XtraGrid.Views.Base; using DevExpress
我是一名优秀的程序员,十分优秀!