KB Article A381
Visible to All Users

How to prevent group rows from being selected in multi-select mode

Description:
How to prevent group rows from being selected in multi-select mode?

Answer:
You can deselect group rows inside the SelectionChanged event handler.
Here is the necessary code for the XtraGrid v2:

Visual Basic
Private Sub GridView1_SelectionChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.SelectionChangedEventArgs) Handles GridView1.SelectionChanged Dim View As GridView = CType(sender, GridView) If e.Added AndAlso View.IsGroupRow(e.RowHandle) Then View.UnselectRow(e.RowHandle) End If If e.AllSelectionChanged AndAlso View.SelectedRowsCount > 0 Then Dim Row As Integer For Each Row In View.GetSelectedRows() If View.IsGroupRow(Row) Then View.UnselectRow(Row) Next End If End Sub

The code for the XtraGrid v3:

C#
bool isRunning = false; private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { if(isRunning) return; isRunning = true; GridView View = sender as GridView; if(e.Action == CollectionChangeAction.Add && View.IsGroupRow(e.ControllerRow)) { View.UnselectRow(e.ControllerRow); } if(e.Action == CollectionChangeAction.Refresh && View.SelectedRowsCount > 0) { View.BeginSelection(); foreach(int Row in View.GetSelectedRows()) { if(View.IsGroupRow(Row)) View.UnselectRow(Row); } View.EndSelection(); } isRunning = false; }
Visual Basic
Dim IsRunning As Boolean = False Private Sub GridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As DevExpress.Data.SelectionChangedEventArgs) Handles GridView1.SelectionChanged If IsRunning Then Return IsRunning = True Dim View As GridView = CType(sender, GridView) If e.Action = System.ComponentModel.CollectionChangeAction.Add AndAlso View.IsGroupRow(e.ControllerRow) Then View.UnselectRow(e.ControllerRow) End If If e.Action = System.ComponentModel.CollectionChangeAction.Refresh AndAlso View.SelectedRowsCount > 0 Then View.BeginSelection() Dim Row As Integer For Each Row In View.GetSelectedRows() If (View.IsGroupRow(Row)) Then View.UnselectRow(Row) Next View.EndSelection() End If IsRunning = False End Sub

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.