Bug Report B199516
Visible to All Users

ASPxGridView - SelectionChanged event fires twice when selecting rows manually, and once when selection is performed on the client side

created 14 years ago

I attached a demo project to this ticket.
Here are the steps to recreate the issue:

  1. Click on the first row of the grid. You will see that the ASPxClientGridView.SelectionChanged event was fired once, and that the ASPxClientGridViewSelectionEventArgs were correct (e.visibleIndex = 0 and e.isSelected = true).
  2. Click on the second row of the grid. This time, the ASPxClientGridView.SelectionChanged event was fired twice, once because a row 0 becomes unselected and once because row 1 becomes selected. For the selected row, the ASPxClientGridViewSelectionEventArgs are ok (e.visibleIndex = 1 and e.isSelected = true), but for the unselected row, we are missing the visibleIndex (e.visibleIndex = -1 and e.isSelected = false).
    This is the first problem. Here is how to reproduce the second problem:
  3. Select the first row of the grid.
  4. Click the "Select Row 1" button. This will programatically select Row 1 of the grid by calling the SelectRows() method of the grid on client-side.
    You will notice that the ASPxClientGridView.SelectionChanged event was fired only once this time, and only for the unselected row. Row 1 was selected programatically and this is not raising the event for the selected row.
    If I summarize:
    - Why the e.visibleIndex = -1 for the unselected row instead of giving the correct index?
    - Why do we have the SelectionChanged event fired twice when selecting a row with the mouse, and only once when selecting a row programatically?
    Thanks, Normand
Comments (2)
DevExpress Support Team 14 years ago

    Hello Normand,
    I appreciate your detailed report, however the issue you faced is not a bug. If you examine the additional properties of the ASPxClientGridView.SelectionChanged event argument, you will be able to determine why client-side event is raised twice.
    The e.isAllRecordsOnPage property tells you that all records on the page are selected or deselected. That is why the e.visibleIndex equals -1.
    Client-side events are raised for all possible actions, however, the server-side event is raised only once when the form is posted to the server. If we send callbacks often, you will face performance issues. On the client side all events are processed quickly.
    Thanks,
    Vest

    NC NC
    Normand Carbonneau 14 years ago

      Hi Vest,
      Thanks for your fast answer. But I still do not understand. First, I understand the client-side event fired twice, and this is perfect.
      What I do not understand is this sentence in your answer:
      "The e.isAllRecordsOnPage property tells you that all records on the page are selected or deselected. That is why the e.visibleIndex equals -1."
      What is the relation between isAllRecordsOnPage and visibleIndex?
      And the other thing I do not understand is why the SelectRows() client-side method does not fire the SelectedIndexChanged client-side event of the grid?
      Thanks, Normand

      Answers

      created 14 years ago

      Normand,
      When both selection properties are enabled, the grid clears all records when you click a row. That is why the ASPxClientGridView.SelectionChanged event is raised. It simply tells that all records were unselected. The e.visibleIndex equals -1, because all rows were unselected.
      Client-side methods do not raise events, because you change the control's state programmatically. We raise events when a user clicks or types something, because this process happens randomly.
      You can handle the selection changing in the following manner:

      JavaScript
      grid.SelectRowOnPage (1); // the second row DoSomething(1); // with the second row

      Thanks,
      Vest

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

          You are always welcome Normand.
          Thank you for your feedback regarding our web site :)
          Thanks,
          Vest

            Hi,

            Picking up on this.  If we use something like :

            function OnMasterSelectionChanged(s, e) {
                    //if(e.isSelected == true)
                        callbackPanelDetails.PerformCallback();
                }

            how can we then at the serverside different between a "select" (in which case data should be loaded) and a "unselect" in which case data should not be loaded? the gridXXX.Selection.Count seems to be 1 even for unselect and the visible index does not seem to be available?

            BR,
            Patrik Johansson

            DevExpress Support Team 7 years ago

              Hello,

              I've created a separate ticket on your behalf (ASPxGridView - How can we then at the serverside different between a "select" and a "unselect" in which case data should not be loaded). It has been placed in our processing queue and will be answered shortly.

              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.