Current filter:
                                You should refresh the page.
                                Support Center
                                  • I'm having many problems updating a xtraGrid bound to a List.

                                    In my application a have a List(Of InternalMessages) in a given class.
                                    This list is updated from many threads, and represents all messages received and send through a specifid UDP port in my app.

                                    When a message is received in UDP Port, this message is inserted in this list.
                                    Also, sometimes, the system send messages to UDP port by inserting a message in this list (there's a class observing the list to see if a message needs to be send).

                                    In the first implementation of my app, I tried to bound the List to a xtraGrid by setting the DataSource of my grid to my list.
                                    This, of course, does't work, because I started to have cross-thread operations problems.

                                    After searching I found this thread:

                                    This thread states:
                                    "Said differently, within a background thread you should work with a local copy of the DataSource and pass its clone to the Grid's DataSource when necessary."

                                    So, I changed my app to return a copy of the list every time my grid needs update:

                                    This is the method that insert itens in the list:
                                    Public Sub Add(ByVal item As InternalMsg) Implements ICollection(Of InternalMsg).Add
                                         _cloned = _table.Copy
                                         RaiseEvent MessageAdded(item)
                                    End Sub

                                    This is the method that return a copy of the list to the xtraGrid.
                                    Public ReadOnly Property GetTable
                                            Return _cloned
                                        End Get
                                    End Property

                                    Now, the grid can be updated without problems in this app.

                                    But... when the grid is using groups (grouping by a specific column) the view behaviour is somewhat strange.

                                    If I select a grouping row that is expanded and a message is inserted in the List, the expanded group is colapsed.
                                    Also, if a select a message in a group, and the List is updated, the grid selects the first message in the group when its datasource is updated... changind the row with the focus.

                                    How can I fix this behavior?



                                Hi Luiz,

                                This behavior is correct. In your scenario you assign a new datasource to GridControl. That is why GridView recreates all rows and moves focus to the first row.

                                To solve the problem, save and restore your GridView state as described in the How to preserve the XtraGrid View state Knowledge Base article. An example for this article contains the RefreshHelper class. You can easily add it your project.


                                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