【发布时间】:2023-03-13 22:37:01
【问题描述】:
我有一个网格视图,我需要选择同一行的多个单元格,但如果我单击不同行中的单元格,我必须清除先前的选择并使用最后点击的单元格开始新的选择。
【问题讨论】:
标签: c# winforms gridview devexpress
我有一个网格视图,我需要选择同一行的多个单元格,但如果我单击不同行中的单元格,我必须清除先前的选择并使用最后点击的单元格开始新的选择。
【问题讨论】:
标签: c# winforms gridview devexpress
参考文档:Multiple Row and Cell Selection
要启用多单元格选择模式,请设置 ColumnViewOptionsSelection.MultiSelect 属性到
true和 GridOptionsSelection.MultiSelectMode 属性 GridMultiSelectMode.CellSelect.
注意:这种选择模式由GridView 和BandedGridView 支持,允许最终用户选择连续的单元格块以及不同行中的单个单元格。
参考资料:
XtraGrid Multiselect Cell
Cut multiple cells in a XtraGrid and Multi Select Drag & Drop data rows into another grid
示例代码sn-p:
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e) {
if(e.Control && !e.Alt && !e.Shift && (e.KeyCode == Keys.Home || e.KeyCode == Keys.End)) {
ColumnView view = ((GridControl)sender).FocusedView as ColumnView;
if(view != null)
view.ClearSelection();
}
}
【讨论】: