Mat posted on Sunday, October 29, 2006
I've been tearing my hair out with this one for a short while, and found nothing in the forum archives to help me along, so thought I'd document it for others.
I have a DataGridView, containing a ComboBox roughly following the Project Edit section of the Windows Forms UI chapter of the book.
On closing my dialog, I get the following error dialog, numerous times:
"DataGridView Default Error Dialog
The following exception occurred in the DataGridView:
System.ArgumentException: DataGridViewComboBoxCell value is not valid.
To replace this default dialog please handle the DataError event."
All well and good, but what is the cause, and how to fix it!
A good bit of googling reveled a blog entry at
http://devauthority.com/blogs/jwooley/archive/2005/12/02/638.aspx. Basically, the grid is still bound to its data source, when the ComboBox's data source is disposed.
Rather than taking the approach of messing with the dispose function, I solved the problem by fiddling with ordering of initialisation of the binding sources. This is in the InitializeComponent function, inside the Form.Designer.cs file.
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.dataGridBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.comboBoxBindingSource = new System.Windows.Forms.BindingSource(this.components);
...
Hope this is useful to someone, should they come across the same problem.
Mat