我有一个 DevExpressXtraGrid http://devexpress.com/Products/NET/Controls/WinForms/Grid/具有三列和一个未绑定的 checkBoxEdit 列的控件,供用户在从网格中删除项目时进行选择。我可以在 xtraGrid 上添加 checkBoxEdit。但是,我不知道如何删除所选列表的主键。任何想法都受到高度赞赏。谢谢
我相信您可以使用以下方法:
void InitGrid() {
gridControl1.DataSource = new List<Person> {
new Person(){ ID = 0 },
new Person(){ ID = 1 },
new Person(){ ID = 2 }
};
gridView.Columns["ID"].Visible = false;
gridView.Columns.Add(new DevExpress.XtraGrid.Columns.GridColumn()
{
UnboundType = DevExpress.Data.UnboundColumnType.Boolean,
Caption = "Mark as Deleted",
FieldName = "IsDeleted",
Visible = true,
});
}
IDictionary<int, object> selectedRows = new Dictionary<int, object>();
void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
int id = (int)gridView.GetListSourceRowCellValue(e.ListSourceRowIndex, gridView.Columns["ID"]);
if(e.IsGetData)
e.Value = selectedRows.ContainsKey(id);
else {
if(!(bool)e.Value)
selectedRows.Remove(id);
else selectedRows.Add(id, e.Row);
}
}
void OnDelete(object sender, System.EventArgs e) {
//... Here you can iterate thought selectedRows dictionary
}
//
class Person {
public int ID { get; set; }
public string Name { get; set; }
public string Age { get; set; }
}
相关帮助主题:
- ColumnView.CustomUnboundColumnData 事件 http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsBaseColumnView_CustomUnboundColumnDatatopic
- ColumnView.GetListSourceRowCellValue 方法 http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsBaseColumnView_GetListSourceRowCellValuetopic946
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)