I encountered this error whenever components.dispose() is called in a windows form with DataGridView. Components.dispose() is called in the Dispose function after form_Closed event, when I quit the application.
The following exception occured in the DataGridView:
System.IndexOutOfRangeException: Index 0 does not have a value. at System.Windows.Forms.CurrencyManager.get_item(Int32 Index) at System.Windows.Forms.DataGridViewDataConnection.GetError(Int32 rowIndex)
To replace this default dialog please handle the DataError event.
I suspect the CurrencyManager isn't synchronized correctly with datagridview data source. Hence, it still tries to synchronize thinking there are items in the data source when in actuality, the items have already been disposed.
Solution 1
Set the tabStop property of datagridview to False. This prevents the datagridview to be 'tab-able'
Solution 2
Calling .dispose() on datagridview explicitly
Question
How does tabIndex property influence the CurrencyManager and why does setting tabStop to false allows the CurrencyManager to be synchronized correctly? I have read about Lazy Initialization being the cause but I still don't see the link between lazy initialization, tabIndex and CurrencyManager.