Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridViewComboBoxCell - Allowing values not in the list
 

DataGridViewComboBoxCell - Allowing values not in the list

I've spent a good couple of days trying to sort this one and read many many posts. However, I've not been able to find a specific solution and it has me baffled.

The (C#) scenario is this;

I have a DataGridView that has some cells as DataGridViewComboBoxCell. These have a fixed set of items from which the user can select. However, when populating the DataGridView programatically some of the DataGridViewComboBoxCell's may be loaded with values that are NOT in the DataGridViewComboBoxCell's items lists. I want to have the values showing in the table (albeit with the cell colour changed and the tooltip explaining that the value is invalid) so the user can see the 'bad' value and select the valid value from the drop down list.

Therefore, I dont want to add the 'bad' value to the dropdown list. All I want is for the DataGridViewComboBoxCell to display a value not in it's list (I can deal with the cell style/tooltip etc).

The nearest I've got so far is handling the DataError event that is raised. I ignore it, but (as others have said) the value shown gets changed to the first value in the Items list...

The DataGridView is bound to a DataTable, which is loaded from a file; no database binding. And the DataGridViewComboBoxCell list loaded when the DataGridView cell is created during a RowsAdded event.

I'm fast coming to the conclusion that the DataGridViewComboBoxCell is not going to do it for me, so the main question is; how have others resolved this?A custom control implementing IDataGridViewEditingControl (Which gets hairy, as i found while coding a Date selection control...) etc?

Thanks all (and many apologies if i HAVE missed the exact answer somewhere :-))

Vectis
  • Edited byvectis Tuesday, September 15, 2009 8:28 PMclarification
  •  
vectis  Tuesday, September 15, 2009 8:26 PM
You could try binding to a generic list instead of a datatable. Put the values from the datatable in the list in addition to any other entries you want displayed.

Hope this helps.

www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Thursday, September 17, 2009 3:12 AM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview - pressed should be Uppercase
• datagridview master detail
• getting error when deleting a row from an MSDE database using datagrid control
• Can you have a Parent/Child relationship in a single datagrid?
• datagridview cell empty
• How to: Bind ComboBox to a database column
• Designer.cs file contains private field that is never used.
• Databinding an XML file to a menu
• Data Grid view Combo Collection filling
• Problem with editing cells in dataGridView