C# 带有checkBoxEdit列的DevExpress XtraGrid控件
我有一个DevExpress控件,有三列和一个未绑定的checkBoxEdit列,供用户在从网格中删除项目时选择。我可以在xtraGrid上添加checkBoxEdit。但是,我不知道如何删除所选列表的主键。任何想法都将受到高度赞赏。谢谢我相信您可以使用以下方法:C# 带有checkBoxEdit列的DevExpress XtraGrid控件,c#,winforms,devexpress,xtragrid,C#,Winforms,Devexpress,Xtragrid,我有一个DevExpress控件,有三列和一个未绑定的checkBoxEdit列,供用户在从网格中删除项目时选择。我可以在xtraGrid上添加checkBoxEdit。但是,我不知道如何删除所选列表的主键。任何想法都将受到高度赞赏。谢谢我相信您可以使用以下方法: void InitGrid() { gridControl1.DataSource = new List<Person> { new Person(){ ID = 0 }, ne
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; }
}
void InitGrid(){
gridControl1.DataSource=新列表{
new Person(){ID=0},
new Person(){ID=1},
new Person(){ID=2}
};
gridView.Columns[“ID”]。Visible=false;
gridView.Columns.Add(新的DevExpress.XtraGrid.Columns.GridColumn()
{
UnboundType=DevExpress.Data.UnboundColumnType.Boolean,
Caption=“标记为已删除”,
FieldName=“IsDeleted”,
可见=真,
});
}
IDictionary selectedRows=新字典();
void gridView1_CustomUnboundColumnData(对象发送方,CustomColumnDataEventArgs e){
int id=(int)gridView.GetListSourceRowCellValue(e.ListSourceRowIndex,gridView.Columns[“id”]);
if(例如IsGetData)
e、 值=selectedRows.ContainsKey(id);
否则{
如果(!(布尔)e.值)
选择删除。删除(id);
else selectedRows.Add(id,e.Row);
}
}
void OnDelete(对象发送方,System.EventArgs e){
//…在这里,你可以反复阅读思想精选词典
}
//
班主任{
公共int ID{get;set;}
公共字符串名称{get;set;}
公共字符串年龄{get;set;}
}
相关帮助主题:
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; }
}
void InitGrid(){
gridControl1.DataSource=新列表{
new Person(){ID=0},
new Person(){ID=1},
new Person(){ID=2}
};
gridView.Columns[“ID”]。Visible=false;
gridView.Columns.Add(新的DevExpress.XtraGrid.Columns.GridColumn()
{
UnboundType=DevExpress.Data.UnboundColumnType.Boolean,
Caption=“标记为已删除”,
FieldName=“IsDeleted”,
可见=真,
});
}
IDictionary selectedRows=新字典();
void gridView1_CustomUnboundColumnData(对象发送方,CustomColumnDataEventArgs e){
int id=(int)gridView.GetListSourceRowCellValue(e.ListSourceRowIndex,gridView.Columns[“id”]);
if(例如IsGetData)
e、 值=selectedRows.ContainsKey(id);
否则{
如果(!(布尔)e.值)
选择删除。删除(id);
else selectedRows.Add(id,e.Row);
}
}
void OnDelete(对象发送方,System.EventArgs e){
//…在这里,你可以反复阅读思想精选词典
}
//
班主任{
公共int ID{get;set;}
公共字符串名称{get;set;}
公共字符串年龄{get;set;}
}
相关帮助主题: