views:

277

answers:

0

I need to have a DataGridView with a ComboBox column. The DataPropertyName is a text column from a dataset. The combobox contains a few values (in a separate dataset) that the user should be able to select, the displaymember and valuemember is the same column.

Now, my problem is that the table beeing edited contains some values in the text column that's not present in the combobox datasource. This gives me a data error exception on the datagrid. I now have the strange situation that my grid should accept these old (and incorrect values), but the user should only be able to select a new and correct value when editing or creating new rows. This was a but cumbersome to explain, I'll add an example.

Data table beeing edited:

Number     Value
--------------------
1          One
2          Two
3          Three
4          Two
5          Three

ComboBox datasource:

LegalValues
---------------------
Two
Three

DataGridView has textbox column Number and ComboBox column Value ComboBox has displaymember and valuemember LegalValues

This will make data datagridview throw an exception on row 1 since 'One' is not present in the combobox dropdown list. Is there any way to avoid that, and just make the 'One' value beeing displayed, but only having 'Two' and 'Three' as possible choises when editing or adding new rows ?