2

I am using DevExpress controls. I have a GridControl with column having CheckboxRepository. I want to display text with checkbox(Text+Checkbox) in column. How can I achieve it?

Irshad
  • 3,071
  • 5
  • 30
  • 51
NJ Bhanushali
  • 901
  • 1
  • 12
  • 21

1 Answers1

1

Take a look: How to display custom text next to a check box within the same cell

This task can be achieved by handling the following GridView/TreeList events: the CustomDrawCell event (CustomDrawNodeCell for the TreeList control) and the ShownEditor event. Within the CustomDraw~ event you should draw a checkbox and the necessary caption:

private void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e) 
{
    if (e.Column != treeList1.Columns["Check"])
        return;

    string caption = "Node ID: " + e.Node.Id.ToString();
    DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo viewInfo = (e.EditViewInfo as DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo);

    DevExpress.Utils.Drawing.CheckObjectInfoArgs checkInfo = viewInfo.CheckInfo;

    checkInfo.Caption = caption;
    checkInfo.Graphics = e.Graphics;
    viewInfo.CheckPainter.CalcObjectBounds(checkInfo);
}

The ShownEditor event handler should adjust the editor's Properties.Caption property when the editor is being activated:

private void treeList1_ShownEditor(object sender, System.EventArgs e) 
{
    DevExpress.XtraTreeList.TreeList tl = sender as DevExpress.XtraTreeList.TreeList;

    if (tl.FocusedColumn != tl.Columns["Check"])
        return;

    (tl.ActiveEditor as DevExpress.XtraEditors.CheckEdit).Properties.Caption = "Node ID: " + tl.FocusedNode.Id.ToString();
}
Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92