【问题标题】:How can I select multiples cell of the same row in a grid view?如何在网格视图中选择同一行的多个单元格?
【发布时间】:2023-03-13 22:37:01
【问题描述】:

我有一个网格视图,我需要选择同一行的多个单元格,但如果我单击不同行中的单元格,我必须清除先前的选择并使用最后点击的单元格开始新的选择。

【问题讨论】:

    标签: c# winforms gridview devexpress


    【解决方案1】:

    参考文档:Multiple Row and Cell Selection

    要启用多单元格选择模式,请设置 ColumnViewOptionsSelection.MultiSelect 属性到 trueGridOptionsSelection.MultiSelectMode 属性 GridMultiSelectMode.CellSelect.

    注意:这种选择模式由GridViewBandedGridView 支持,允许最终用户选择连续的单元格块以及不同行中的单个单元格。

    参考资料:
    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();
        }
    }
    

    【讨论】:

    • 感谢您的快速回答,但它不起作用,我实现了 ProcessGridKey 事件,但我一直选择不同行的单元格。我认为我的问题不够清楚,我需要选择同一行的多个单元格,但是如果我单击不同行中的单元格,我必须清除先前的选择并使用最后点击的单元格开始新的选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 2011-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多