如何在GridView列中添加带有复选框存储库的文本?

时间:2015-09-15 11:17:23

标签: c# winforms devexpress-windows-ui

我正在使用DevExpress控件。我有一个GridControl,其列为CheckboxRepository。我想在列中显示带复选框(文本+复选框)的文本。 我怎样才能实现它?

1 个答案:

答案 0 :(得分:1)

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

  

可以通过处理以下GridView / TreeList来实现此任务   events:CustomDrawCell事件(TreeList的CustomDrawNodeCell   控制)和ShownEditor事件。在CustomDraw~事件中你   应绘制一个复选框和必要的标题:

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);
}
  

ShownEditor事件处理程序应调整编辑器   激活编辑器时的Properties.Caption属性:

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();
}