I have drawn a checkbox in devexpress grid group row using the code below.
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();
}
However, I am having challenges in accessing the checkbox to tick and untick.
I tried to use GridHitInfo in GridView click event (as below). But I am not getting anything that could help me to access the checkbox.
void gvWorkspaces_Click(object sender, EventArgs e) {
GridView view = (GridView)sender;
Point pt = view.GridControl.PointToClient(Control.MousePosition);
GridHitInfo info = view.CalcHitInfo(pt);
}
Any help would be appreciated.
Thanks
Balan
Best Answer
You should use the following approach: