It is a new .NET 3.5 application in VisualStudio 2008.
I have added to a main form following components
BindingSource bsData // bsData.DataSource = ds
DataGridView dgvResultset // dgvResultset.DataSource = bsData
Then, I execute some WMI query, cleanup all from "ds" DataSet, then creating a new DataTable (TableName="Record") in the "ds" DataSet.
Then call some method to re-bind "ds" DataSet to a BindingSource and refresh DataGridView.
The thing I need - is read-only DataGridView object showing data from a DataTable object which is in the "ds" DataSet object.
The 1st data displaying works fine.
BUT(!!!) the problem is - on every next data refresh it is reporting lot of stupid errors:
20120919,192131.61 [T9] DataGridView->Error(System.IndexOutOfRangeException): Index 2 does not have a value.
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 rowIndex)
The "Index" value is usually different between data reloads. So, 1st data load is ok, on next data reload it reports N errors with Index = 0, then on next data reload it reports N errors with Index = 4, then Index = 2 and so on. Seems Index value is walking in some random range.
I have placed my own DataError event handler, like this:
private void dgvResultset_DataError(object sender, DataGridViewDataErrorEventArgs e)
e.Cancel = true;
e.ThrowException = false;
Trace.WriteLineIf(TrcLvl.TraceError, TrcLvl.TraceError ? String.Format(
) : "");
But that only suppressed an error, not solved it. So, all the time on next data re-loads it is reporting tons of that stupid errors. :-\
The questions are
how to get rid of that error?!
why that error is happening at all?! I assume if DataGridView is marked ReadOnly and BindingSource has AllowNew = false it should not try to do anything with Grid data, so should not be any reasons for mentioned errors...
Also - the main problem is not the mentioned error itself but that application is hanging after 3-5 query executions. I assume that is happened because of that error, somewhere inside a DataGridView. That is why I'm trying to figure out - how to get rid of that error.