如何在 GridView 列中使用复选框存储库添加文本?
How to add text with checkbox repository in GridView column?
我正在使用 DevExpress
控件。我有一个 GridControl
,列有 CheckboxRepository
。我想在列中显示带有复选框(文本+复选框)的文本。
我怎样才能实现它?
看看: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();
}
我正在使用 DevExpress
控件。我有一个 GridControl
,列有 CheckboxRepository
。我想在列中显示带有复选框(文本+复选框)的文本。
我怎样才能实现它?
看看: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();
}