2012-04-27 92 views
1

我有一个DevExpress XtraGrid控件,有三列和一个未绑定的checkBoxEdit列供用户从网格中删除项目时选择。我可以在xtraGrid上添加checkBoxEdit。但是,我不知道如何让选定列表的主键被删除。任何想法是高度赞赏。由于DevExpress XtraGrid Control with checkBoxEdit列

+0

什么技术(asp.net,ASP。净mvc,WPF,WinForms)? – 2012-04-27 12:21:11

+0

感谢您的回复。我正在使用WinForms – aby 2012-04-27 12:25:45

+0

考虑使用布尔属性扩展数据对象,例如“markdeleted”。不再需要一个未绑定的列及其基础结构代码。 – 2012-04-27 16:02:39

回答

4

我相信你可以用下面的办法:

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

相关帮助主题:

+0

非常感谢。它像一个魅力! – aby 2012-04-28 09:38:14

+0

@ user758961:[你应该总是接受正确的答案](http://stackoverflow.com/faq#howtoask) – DmitryG 2012-04-28 09:53:04

相关问题