How to detect the change in a datagridviewcomboboxcolumn in a new datagridview row?
Posted on 2007-03-27
How to detect the change in a datagridviewcomboboxcolumn unbound column in a new row? I have 2 datagridviews on a form. The first grid has a several columns bound to a dataset with the addition of a datagridviewcomboboxcolumn inserted. (Side note, even though I inserted it at column index 0 and it displays first in the grid, its actual index is 6 for some reason). The datagridviewcomboboxcolumn is bound to a list of items in a datatable. What I want to happen is when a user selects a new value in this column in a new row or changes a value in this column on an existing row for and event to fire. In this event I need to add some rows orupdate some rows in datagridview2 based on the value in the datagridviewcomboboxcolumn. I have been trying to use this approach:
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim cb As ComboBox = e.Control
If Not cb Is Nothing Then
' first remove event handler to keep from attaching multiple:
RemoveHandler cb.SelectedIndexChanged, AddressOf Me.editingComboBox_SelectedIndexChanged
' now attach the event handler
AddHandler cb.SelectedIndexChanged, AddressOf Me.editingComboBox_SelectedIndexChanged
Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
The problem with this approach is this event gets fired for every row in the datagridview, not just the current row and then only after the focus has moved to a new "new row". It does not fire on the actual change of the selection in the combocolumn. I can't seem to find a list of the events in the order they happen when a user selects an item in a datagridviewcomboboxcolumn in a new row.