C# 使用Dev控件为gridView添加复选框,实现多选和单选

C# 使用Dev控件为gridView添加复选框,实现多选和单选,代码如下:

1 this.gridControl1.DataSource = dtss;
2                     gridView1.OptionsSelection.MultiSelect = true;
3 
4                     gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
5 
6                     gridView1.OptionsSelection.ShowCheckBoxSelectorInColumnHeader = DevExpress.Utils.DefaultBoolean.True;

如图所示样式:

 

 获取选中的数据:

 1 for (int i = 0; i < this.gridView1.RowCount; i++)
 2                 {
 3 
 4                     if (this.gridView1.IsRowSelected(i))
 5                     {
 6                         ZYDModel mo = new ZYDModel();
 7                         mo.JH = this.gridView1.GetDataRow(i)["标题1"].ToString();
 8                         mo.RQ = this.gridView1.GetDataRow(i)["标题2"].ToString();
 9                         mo.YGNUM = this.gridView1.GetDataRow(i)["标题3"].ToString();
10                         mo.CYGNUM = this.gridView1.GetDataRow(i)["标题4"].ToString();
11                         mo.ZYD = this.gridView1.GetDataRow(i)["标题5"].ToString();
12                                             }

 

posted @ 2020-06-04 18:22  幸运(● ̄(エ) ̄●)  阅读(4395)  评论(0编辑  收藏  举报
Document