Csharp/C#教程:使用checkBoxEdit列的DevExpress XtraGrid控件分享


使用checkBoxEdit列的DevExpress XtraGrid控件

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

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

void InitGrid() { gridControl1.DataSource = new List { 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 selectedRows = new Dictionary(); 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; } } 

相关帮助主题:

上述就是C#学习教程:使用checkBoxEdit列的DevExpress XtraGrid控件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/950740.html

(0)
上一篇 2021年11月17日
下一篇 2021年11月17日

精彩推荐