DevExpress XtraGrid控件与checkBoxEdit列 [英] DevExpress XtraGrid Control with checkBoxEdit column

查看:598
本文介绍了DevExpress XtraGrid控件与checkBoxEdit列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DevExpress XtraGrid 控件,带有三列和未绑定checkBoxEdit列,供用户从网格中删除项目时选择。我可以在xtraGrid上添加checkBoxEdit。但是,我没有任何想法,我可以如何获取所选列表的主键被删除。任何想法都非常感激。谢谢

I've a DevExpress XtraGrid control with three columns and a unbound checkBoxEdit column for users to select when deleting items from the grid. I'm able to add the checkBoxEdit on the xtraGrid. However, i don't have any idea as to how i can get the selected lists' primary key(s) to be deleted. Any idea is highly appreciated. Thanks

推荐答案

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

I believe you can use the following approach:

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 Event
  • ColumnView.GetListSourceRowCellValue Method

这篇关于DevExpress XtraGrid控件与checkBoxEdit列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆