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