Binding to a DataGridView's DataGridViewComboBoxColumn

Aug 7 2008 2:28 PM
I am using .NET 2.0

I have problem that I am hoping someone here can help me with. It involves using the DataGridViewComboBoxCell in a different way than what was intended by its designers.

I am binding the DataGridView control to a table in a dataset. I set the DataGridViewColumn's DataMember property to a column of my DataTable. One column of my DataGridView is of type DataGridViewComboBoxColumn. I set the DataGridViewComboBoxColumn.DataSource to something like {"one", "two", "three"}

The DataTable column I bind to the DataGridViewComboBoxColumn will have valid values in it so that they match one of the options "one", "two", or "three". Sometimes they might have something like "foo" in them, that do not match one of the options. I subscribe to the DataGridView's DataError event so to handle the error.The default behavior for the DataGridViewComboBoxCell is to select the first option in the list when there was an error. I want a different behavior.

The desired behavior would be to show the invalid value in the cell and change the background color of the cell to red and effectively have the DataGridViewComboBoxColumn selected index = -1;

Anyone have an idea how to implement this?