DevExpress Grid使用checkBox选中的方法

到官网得到消息自13.2版本后的Dev Grid中均内置了CheckBox列多选功能。在寻找答案的过程的成果进行记录。

一、13.2版本以后用法

    1. 启用多选列 
      对Gird中的View进行以下属性设置: 
      gridView1.OptionsSelection.MultiSelect = true;
       gridView1.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowSelect;
    2. 清除当前选择 
      在选中列时后,可配置在选中列以外的地方点击时候会清除当前的选择。14以后才有此功能 
      gridView1.OptionsSelection.ResetSelectionClickOutsideCheckboxSelector = true;
    3. 获取选中的行

      二、早起版本实现

      相关链接:http://www.devexpress.com/Support/Center/Example/Details/E1271

      1. GridCheckMarksSelection类 
          1 public class GridCheckMarksSelection {
          2         protected GridView _view; 3 protected ArrayList selection; 4 GridColumn column; 5 RepositoryItemCheckEdit edit; 6 const int CheckboxIndent = 4; 7 8 public GridCheckMarksSelection() { 9 selection = new ArrayList(); 10 } 11 12 public GridCheckMarksSelection(GridView view) : this() { 13 View = view; 14 } 15 public GridView View { 16 get { return _view; } 17 set { 18 if (_view != value) { 19 Detach(); 20 Attach(value); 21 } 22 } 23 } 24 public GridColumn CheckMarkColumn { get { return column; } } 25 26 public int SelectedCount { get { return selection.Count; } } 27 public object GetSelectedRow(int index) { 28 return selection[index]; 29 } 30 public int GetSelectedIndex(object row) { 31 return selection.IndexOf(row); 32 } 33 public void ClearSelection() { 34 selection.Clear(); 35 Invalidate(); 36 } 37 public void SelectAll() { 38 selection.Clear(); 39 // fast (won't work if the grid is filtered) 40 //if(_view.DataSource is ICollection) 41 // selection.AddRange(((ICollection)_view.DataSource)); 42 //else 43 // slow: 44 for (int i = 0; i < _view.DataRowCount; i++) 45 selection.Add(_view.GetRow(i)); 46 Invalidate(); 47 } 48 public void SelectGroup(int rowHandle, bool select) { 49 if (IsGroupRowSelected(rowHandle) && select) return; 50 for (int i = 0; i < _view.GetChildRowCount(rowHandle); i++) { 51 int childRowHandle = _view.GetChildRowHandle(rowHandle, i); 52 if (_view.IsGroupRow(childRowHandle)) 53 SelectGroup(childRowHandle, select); 54 else 55 SelectRow(childRowHandle, select, false); 56 } 57 Invalidate(); 58 } 59 public void SelectRow(int rowHandle, bool select) { 60 SelectRow(rowHandle, select, true); 61 } 62 public void InvertRowSelection(int rowHandle) { 63 if (View.IsDataRow(rowHandle)) { 64 SelectRow(rowHandle, !IsRowSelected(rowHandle)); 65 } 66 if (View.IsGroupRow(rowHandle)) { 67 SelectGroup(rowHandle, !IsGroupRowSelected(rowHandle)); 68 } 69 } 70 public bool IsGroupRowSelected(int rowHandle) { 

转载于:https://www.cnblogs.com/xihong2014/p/10756820.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值