如何在网格视图中选择同一行的多个单元格?

时间:2017-09-06 13:29:08

标签: c# winforms gridview devexpress

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

1 个答案:

答案 0 :(得分:0)

请参阅文档:Multiple Row and Cell Selection

  

要启用多个小区选择模式,请设置   ColumnViewOptionsSelection.MultiSelect属性trueGridView   GridOptionsSelection.MultiSelectMode财产到   GridMultiSelectMode.CellSelect

注意:此选择模式由BandedGridViewusing 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(); } } 支持,允许最终用户选择连续的单元格块以及不同行中的单个单元格。

<强>参考文献:
XtraGrid Multiselect Cell
Cut multiple cells in a XtraGrid and Multi Select Drag & Drop data rows into another grid

示例代码段:

public List<string> GetChangedProperties<T>(object A, object B)
{
    if (A != null && B != null)
    {
        var type = typeof(T);
        var allProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
        var allSimpleProperties = allProperties.Where(pi => pi.PropertyType.IsSimpleType());
        var unequalProperties =
               from pi in allSimpleProperties
               let AValue = type.GetProperty(pi.Name).GetValue(A, null)
               let BValue = type.GetProperty(pi.Name).GetValue(B, null)
               where AValue != BValue && (AValue == null || !AValue.Equals(BValue))
               select pi.Name;
        return unequalProperties.ToList();
    }
    else
    {
        throw new ArgumentNullException("You need to provide 2 non-null objects");
    }
}