Current filter:
                                You should refresh the page.
                                Support Center
                                  • If I understand correctly, if a grid is multiSelect = true, then we should use SelectionChanged if we want to capture the row selection changing. If a grid is multiSelect = false, then SelectionChanged does not fire; rather we should use FocusedRowChanged.

                                    Here is my issue:

                                    I need my gridview to programmatically change between multiSelect being on or off. I also need to know when the selected rows change.

                                    I cannot seem to exclusively use selectionChanged or focusedRowChanged.

                                    If I use SelectionChanged, then when multiSelect is off, the event does not fire (as expected).

                                    I then tried to use focusedRowChanged, but if you do a gridview.GetSelectedRows(), it gives incorrect results when multiSelect is enabled (I am guessing that focusedRow property gets updated before SelectedRows, because it always 'lags behind' by one) If this is unclear, I can provide a sample.

                                    So in this situation, is my only option to handle both events, and then I will have to choose to always ignore one of them, based on whether the grid is multiselect or not? If this is the case, then I would like to submit a request to either support SelectionChanged even when multiselect is off, or to update whatever property GetSelectedRows() returns, before triggering the focusedRowChanged event.


                                • Hi,

                                  Thank you for contacting us.

                                  I am afraid that the issue you have experienced is not quite clear to me.

                                  I have created simple sample based on your description and it seems that everything worked as expected on my side.

                                  Would you please illustrate with my sample the problematic behavior, or provide us with yours.

                                  We are looking forward to your feedback.

                                • Brian Turner1 08.22.2012

                                  Hi Oleg,

                                  Thank you for your response.

                                  The sample that you posted runs fine.

                                  The problem is, I have business logic that is triggered when the user 'clicks on a different row' it SelectionChanged, FocusedRowChanged, whatever. Because of this situation where I need to go between multiSelect true and false, I need to handle both of these events, like in the sample you provided. But I don't want my business logic to trigger twice, so ideally I could just handle the FocusedRowChanged event.

                                  So do this: Remove your selectionChanged event, modify the FocusedRowChanged event to the below, and then run the code and enable multi select. see what happens when you change rows.

                                   private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
                                              labelControl1.Text = "Focus state: focused row - " + gridView1.FocusedRowHandle.ToString();

                                              labelControl2.Text = "Selection state: selected row - " + gridView1.GetSelectedRows().FirstOrDefault();

                                  Long story short, if you call GetSelectedRows from within a FocusedRowChanged event, it returns the wrong value(s).

                                1 Solution

                                Creation Date Rating Importance Sort by

                                Hi Brian,

                                Here is the code which fixes this issue in the project:

                                private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { BeginInvoke(new MethodInvoker(delegate { labelControl1.Text = "Focus state: focused row - " + gridView1.FocusedRowHandle.ToString(); labelControl2.Text = "Selection state: selected row - " + gridView1.GetSelectedRows().FirstOrDefault(); } )); }

                                I.e. you need to obtain data after a small delay. Does this solution work for you?

                                • Brian Turner1 08.23.2012

                                  Thank you very much, that works and is extremely helpful.

                                  Can this be reported as a bug? Or at least a documentation change somewhere, if it is not already documented?

                                • This behavior is correct. As described in the ColumnView.SelectionChanged Event help article, this event "Fires when row/cell selection is changed in multiple selection mode."

                                  About obtaining selected rows via the FocusedRowChanged event handler. GridControl first moves focus to a row and then selects it. I will ask our Documentation team to add this information into our documentation.

                                • Rachel Lim 2 08.07.2013

                                  This does not appear to work when you unselect an item while MultiSelect = true since unselecting an item doesn't necessary trigger the FocusRowChanged event

                                • Hi Rachel,
                                  Yes, you are right. But there is no actual relation between focused and selected rows. A focused row is the visual representation of the CurrencyManager.Position, and a selected row is just an array of ordinary rows, which can be highlighted by using the GridView's built-in features. Hence, the GridView cannot exist without focused row, but it can have all rows non-selected (in multi-selection mode). Moreover, I see no problem in realization custom logic, i.e. obtaining selected rows in both modes: you can just check whether or not the GridView is in multi-select mode and extract your logic in a custom method. Please see the code sample above that illustrates this idea:

                                  private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { Test(); } private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if(!gridView1.IsMultiSelect) Test(); } private void Test() { int[] rows = gridView1.GetSelectedRows(); }

                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners