显示分组面板
gridView1.OptionsView.ShowGroupPanel = true;
是否开启多选
gridView1.OptionsSelection.MultiSelect = true;
多选模式(开启多选生效),行选择、单元格选择,CheckBox选择
//单元格选择 gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CellSelect; //整行选择 gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect; //CheckBox选择 gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
CheckBox列宽
gridView1.OptionsSelection.CheckBoxSelectorColumnWidth = 30;
获取CheckBox选中行索引
int[] index = gridView1.GetSelectedRows(); foreach (var item in index) { MessageBox.Show(item.ToString()); }
选中行索引
gridView1.GetSelectedRows()[0]
列宽自动调整
gridView1.OptionsView.ColumnAutoWidth = true;
行高自动调整
gridView1.OptionsView.RowAutoHeight = true;
是否开启编辑
gridView1.OptionsBehavior.Editable = true;
编辑模式
//默认编辑模式,点击鼠标单元格可直接修改 gridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.Default; //弹出窗口编辑 gridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.EditForm; //当前点击行下方弹出编辑面板 gridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.EditFormInplace; //隐藏当前行,出现编辑面板 gridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.EditFormInplaceHideCurrentRow; //默认编辑模式,点击鼠标单元格可直接修改 gridView1.OptionsBehavior.EditingMode = DevExpress.XtraGrid.Views.Grid.GridEditingMode.Inplace;
获取点击单元格值
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { MessageBox.Show(e.CellValue.ToString()); }
获取选中行某一列数据
private void gridView1_RowClick_1(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { string str = gridView1.GetRowCellValue(gridView1.GetSelectedRows()[0], "RegionDescription").ToString(); MessageBox.Show(str); }