【问题标题】:DevExpress XtraGrid Control with checkBoxEdit column带有 checkBoxEdit 列的 DevExpress XtraGrid 控件
【发布时间】:2012-05-08 00:24:43
【问题描述】:

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

【问题讨论】:

  • 什么技术(asp.net,asp.net mvc,WPF,WinForms)?
  • 感谢您的回复。我正在使用 WinForms
  • 考虑使用布尔属性扩展您的数据对象,例如“标记已删除”。不再需要未绑定的列及其基础结构代码。
  • @StephanKeller:未绑定列是扩展数据对象并实现主题启动器描述的功能的敏捷方法。我认为在这种情况下扩展数据源是最糟糕的方法。

标签: c# winforms devexpress xtragrid


【解决方案1】:

我相信您可以使用以下方法:

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

相关帮助主题:

【讨论】:

猜你喜欢
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-06
  • 1970-01-01
相关资源
最近更新 更多