0

i have a bound dataGridView where i load a list of objects using a bindinglist. Each row has a datagridviewcomboboxCell and a textcell. The comboboxes are filled with enum values. Depending on the item selected in the combobox the textcell should have another cellStyle. E.g. if the user selects the first item of the combobox, the cell should be green, if he selects the second item, the cell should be blue, and so on... I implemented Handlers on the dataGridviewComboboxCell when the user adds a new row to the dataGridView. This works perfect using DataGridView.EditingControlShowing event.

But if i bind a list containing objects to the datagridview, the EditingControlShowing event is not fired. So i need to know how i can add the eventhandlers to the datagridviewComboboxCells when the data is loading into the dataGridView (using datasource).

I figured out, that i can use the DataSourceChanged event getting all data, but i can not access the cells control to add a handler.

gegy
  • 87
  • 7
  • 1
    I think you would be better off handling the `CellFormatting` event and checking the cells there and then assign the formats – JayV Nov 18 '20 at 16:04
  • I think you are right. On datasource loading i should set the cellstyle depending on the data. If the user change the item in the combobox, the handler is added and it works like a charm. :) – gegy Nov 18 '20 at 16:22

1 Answers1

0

As JayV posted: I can use CellFormatting on loading the data. If the user change the item in the combobox, then the handler is added to the combobox and it works as it should.

gegy
  • 87
  • 7