What do I do If the value of a datagridviewcombobox is not in the datagridviewcomboboxcolumn datasource?
-
27-10-2019 - |
Question
I've got a situation where the drop down list has to contain only 'active' objects. However this doesn't mean the current combobox value will be in the list (it was selected at a time that object was active, but is not active anymore).
As things are now, there's an exception thrown.. I think in the dataerror handler of the datagridview, that says the value is not in the list.
What I need to do is find some event that is fired when each datagridview row is populated, so I can check and see if the combobox value is in the combobox datasource... if not, I'd add it. That's the only solution I can see. But the question is, which event handler should I use for this?
Preferably, I'd like to be able to generalize this check and put it in a class that inherits from datagridview. This way, I won't have to worry about this problem ever again.
Any ideas?
Isaac
Solution
You could try the DataBindingComplete
event. Other options include DataMemberChanged
and DataSourceChanged
.
It's a bit hard to tell which event would be the most appropriate without seeing some code.