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

本文关键字:复选框 存储 文本 添加 GridView | 更新日期: 2023-09-27 18:12:44

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

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

看一下:如何在同一单元格内的复选框旁边显示自定义文本

这个任务可以通过处理下面的GridView/TreeList来实现事件: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事件处理程序应该调整编辑器的属性。当编辑器被激活时,设置标题属性:

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