Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • 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: http://www.devexpress.com/Support/Center/p/AK2981.aspx.

                                    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
                                         _list.Add(item)
                                         _cloned = _table.Copy
                                         _publisher.Notify()
                                         RaiseEvent MessageAdded(item)
                                    End Sub

                                    This is the method that return a copy of the list to the xtraGrid.
                                    Public ReadOnly Property GetTable
                                        Get
                                            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?

                                    Thanks

                                0

                                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.

                                Thanks
                                Dimitros

                                If you need additional product information, write to us at info@devexpress.com 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, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

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