我认为,您对XtraTreeList 的指示也可以应用于XtraGrid。但我可以向你建议另一种方式。
您可以使用GridView.CustomRowCellEdit 事件和两个ResositoryItemCheckEdit 对象:
private RepositoryItemCheckEdit editTick;
private RepositoryItemCheckEdit editUntick;
只需将Tick 文本设置为editTick.Caption 属性,将Untick 文本设置为editUntick.Caption 属性。
这是一个例子:
//Initialize repository items:
editTick = new RepositoryItemCheckEdit() { GlyphAlignment = HorzAlignment.Near, Caption = "Apples" };
editUntick = new RepositoryItemCheckEdit() { GlyphAlignment = HorzAlignment.Near, Caption = "Bananas" };
//Add handler for CheckedChanged event:
Action<object, EventArgs> action = (s, e) =>
{
var ownerEdit = s as CheckEdit;
if (ownerEdit == null)
return;
ownerEdit.Text = ownerEdit.Checked ? editTick.Caption : editUntick.Caption;
};
editTick.CheckedChanged += new EventHandler(action);
editUntick.CheckedChanged += new EventHandler(action);
//Some sample DataSource:
var table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Bool", typeof(bool));
table.Rows.Add(0, false);
table.Rows.Add(1, false);
table.Rows.Add(2, true);
table.Rows.Add(3, false);
table.Rows.Add(4, true);
table.Rows.Add(5, true);
table.Rows.Add(6, false);
table.Rows.Add(7, true);
gridControl.DataSource = table;
//Here comes the CustomRowCellEdit:
gridView1.CustomRowCellEdit += (s, e) =>
{
if (e.Column.FieldName != "Bool" || e.CellValue == null) //Put your own field name here instead of "Bool".
return;
e.RepositoryItem = (bool)e.CellValue ? editTick : editUntick;
};
//Add CustomColumnDisplayText event, so you can see your "Apples" in group rows and filters:
gridView1.CustomColumnDisplayText += (s, e) =>
{
if (e.Column.FieldName != "Bool")
return;
e.DisplayText = (bool)e.Value ? editTick.Caption : editUntick.Caption;
};