Click to See Complete Forum and Search --> : [RESOLVED] DataGridViewComboBoxColumn change to automatically update DataGridView


tim8w
January 24th, 2010, 10:26 PM
I have a standard DataGridView. One of the columns is a DataGridViewComboBoxColumn. When I select one of the ComboBox items, I want to trap the change and add additional columns based on the item selected in the ComboBox. I've tried using CellValueChanged for the DataGridView column, and a bunch of other events, but none of them is fired when the DataGridViewComboBox value is changed. What event can I trap to make this happen? Right now as I said, I am using CellValueChanged, but of course the event doesn't fire until I click on another cell...

tim8w
January 25th, 2010, 12:35 AM
Here's what I had to end up doing:


Private Sub dgvClass_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvClass.EditingControlShowing
If TypeOf e.Control Is ComboBox Then
Dim combo As ComboBox = DirectCast(e.Control, ComboBox)

If combo IsNot Nothing Then
RemoveHandler combo.SelectedIndexChanged, _
New EventHandler(AddressOf ComboBox_SelectedIndexChanged)


AddHandler combo.SelectedIndexChanged, AddressOf ComboBox_SelectedIndexChanged
End If
End If
End Sub