Description:
The data is updated externally and the new data is only displayed after its row is clicked on, I don't want to refresh the entire grid as this is inefficient. What is the best way to refresh the on-screen data if the datasource is an ArrayList?
Answer:
The best solution is to implement the IBindingList interface in your data object (please see the GridIBindingList tutorial project). In this case, the XtraGrid is automatically notified of any external changes made.
Otherwise, you should disconnect the grid from its data - set DataSource to null (Nothing in VB.NET) and then bind it again. You can also try to call the BeginSort/EndSort methods of a GridView object.
Another way is to refresh the data by calling the LayoutChanged method of a grid view. For example:
C#ArrayList data = new ArrayList();
gridControl1.DataSource = data;
...
data.Add(myObject);
gridControl1.MainView.LayoutChanged();
You will need to explicitly update the CurrencyManager.Position property, when deleting the last row or adding a row to an empty array. Additional information about the IBindingList and CurrencyManager can be found in the MSDN Library.
See Also:
How to resolve the ArgumentOutOfRangeException when deleting an item from the grid's data list
What could be the cause of a serialization error when I save my custom collection which is bound to a grid?