I'm re-posting this in QA from the C# forum to see if I can get a wider response.
I have a datagridview bound to a datatable. I update the datatable quickly and constantly (52 rows, each row updated multiple times per second). The datatable, datagridview, and updates are all done on the same thread and no updates are concurrent, although I feel my issue is caused by updates to the DataTable while the GridView is updating itself from a previous update to the Datatable.
Every so often, usually after a few minutes, I get an exception, here are the details:
Message = "Index was outside the bounds of the array."
Source = "System.Data"
Stack Trace:
at System.Data.Common.StringStorage.Get(Int32 recordNo)
at System.Data.DataColumnPropertyDescriptor.GetValue(Object component) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex)
The program does appear to continue functioning normally regardless of the error. It's driving me mad, has anyone ever encountered this before or have any advice? My only guess is that I think I may be updating the data source so quickly that the control is not finished drawing before I update the data source again. If this is the case, I have a couple of things to try:
I don't really want to throttle the updates because the GUI looks really good right now, but I can if needed.
I could try to un-bind and re-bind the datasource every time I update the datatable, too.
Update 1, I have tried putting a lock on the datagridview and the datatable before updating the datatable. However this had no positive effect.
Update 2, I can add my own handler to the DataError event of the GridView, but it doesn't help with debugging. If I leave out code for the event subscriber it still gets the exception, but the user would never know (I know this is not a solution).
Update 3, Addressing John's questions. My datatable is updated every time I receive a new price that I crack via a socket connection. Here is what the code looks like. Symbol_Feed is a Dictionary<string,>
this.Symbol_Feed[symbol].SetField("BankVar0", quote.BankVar0);
this.Symbol_Feed[symbol].SetField("BankVar1", quote.BankVar1);
this.Symbol_Feed[symbol].SetField("BankVar2", quote.BankVar2);
this.Symbol_Feed[symbol].SetField("BankVar3", quote.BankVar3);
this.Symbol_Feed[symbol].SetField("BankVar4", quote.BankVar4);
this.Symbol_Feed[symbol].SetField("BankVar5", quote.BankVar5);
I had not given the ObservableCollection object any thought yet, but I will now.
I am not adding or deleting rows, only updating existing.