0

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

Isaac Bolinger
  • 7,328
  • 11
  • 52
  • 90

1 Answers1

1

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.

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
  • Not familiar with what the first couple do, I will try them out. – Isaac Bolinger Jan 29 '11 at 05:48
  • I just checked each cell after a datasourcechanged to see if it was a comboboxcell. If it was, I took its valuemember and checked it against the datasource list. If it wasn't in there, I added it. The add seemed to take place in the nick of time.. there wasn't any dataerrors thrown. Thanks Anna! – Isaac Bolinger Jan 29 '11 at 06:38
  • 1
    @IsaacB You could also eliminate a number of cells by first determining which columns are `DataGridViewComboBoxColumn` and only checking cells in those columns. – Adam Lear Jan 29 '11 at 15:17
  • thats true! How lazy of me to check them all. – Isaac Bolinger Jan 30 '11 at 06:34