Ticket T193570
Visible to All Users

GridView SelectionChanged Event - Ignore Outside Checkbox column

created 10 years ago

I have a GridView with a check box column loaded with Rows.
By default I use GridView.SelectAll to "check" all the rows within the Shown event of the form.

When i click inside the Checkbox column of any row, the individual row checks/un-checks properly.

The issue is when clicking (selecting) a row from any column besides the Checkbox column. in this case the selected row always gets "checked" and all other rows get "unchecked".

I would like the GridView.SelectionChanged event to only occur when the users selects the row(s) from within the “CheckBox” column and ignore this event if the row is selected from any other column. Either that or ignore the “checked”/”Un-checked” status of a row when selecting it from outside the Checkbox column.

I have looked over this article but do not infer from it where I could go about obtaining the behavior I am trying to achieve:
https://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsBaseColumnView_SelectionChangedtopic

This article *may* be helpful, but this person is re-loading his data; I am not. In any case I could not try this approach as I have been unable to convert the C# code to VB.NET:
https://www.devexpress.com/Support/Center/Question/Details/T168906

Please see my attachment for more details.

Regards,

Mark

Answers approved by DevExpress Support

created 10 years ago

Hello,
In version 14.1, we've introduced the GridOptionsSelection.ResetSelectionClickOutsideCheckboxSelector property to control this behavior. Is upgrade a suitable option for you?

    Show previous comments (1)
    DevExpress Support Team 10 years ago

      Hello,
      Please try the solution suggested in the CheckBoxRowSelect - Selection is cleared when you click outside of a check box column ticket. It should help.
      Let me know if you need further assistance.

        That worked great!  I will make sure to implement the new property when I get the chance to upgrade.
        I have also included a VB.NET example here of the working solution to this:
           Private Sub grdView_MouseDown(sender As Object, e As MouseEventArgs) Handles grdView.MouseDown
               Dim view As GridView = TryCast(sender, GridView)
               keepSelection(e, view)
           End Sub
           Private Sub grdView_MouseUp(sender As Object, e As MouseEventArgs) Handles grdView.MouseUp
               Dim view As GridView = TryCast(sender, GridView)
               keepSelection(e, view)
           End Sub
           Private Sub keepSelection(e As MouseEventArgs, view As GridView)
                   Dim hi As GridHitInfo = view.CalcHitInfo(e.Location)
                   If hi.Column IsNot Nothing Then
                       If hi.Column.FieldName <> "DX$CheckboxSelectorColumn" Then
                           Dim selRows() As Integer = view.GetSelectedRows()
                           Dim isSelected As Boolean = view.IsRowSelected(hi.RowHandle)
                           BeginInvoke(New Action(Function()
                                                      For i As Integer = 0 To selRows.Length - 1
                                                          view.SelectRow(selRows(i))
                                                      Next
                                                      If Not isSelected Then
                                                          view.UnselectRow(hi.RowHandle)
                                                      End If
                                                  End Function))
                       End If
                   End If
           End Sub

        DevExpress Support Team 10 years ago

          Thank you for sharing your code with us! You cooperation is greatly appreciated.

          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.