I am trying to catch when the value of a combobox in a Datagridview is changed and do something based on the new selected value.
I have found and been using code found in post #4 in this link:
I have slightly modified it so it get the new selected value and does something based on it, I also changed a couple things as the code in the above post only seemed to fire on first selection from the combobox, i.e. if I selected a value then selected a different value without leaving the control the second selection wouldn't fire the event.
Below is where I have got the code up to, it fires every time a section is made within the control however when I try to leave the control it goes into an infinite loop within "editingComboBox_SelectedIndexChanged" Any help to fix the issue with my code or a fix to the original code in the link so it will fire each time a value is selected without leaving the control.
Private Sub dgvEmbroList_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles dgvEmbroList.EditingControlShowing 'Get the Editing Control. I personally prefer Trycast for this as it will not throw an error Dim editingComboBox As ComboBox = TryCast(e.Control, ComboBox) If Not editingComboBox Is Nothing Then 'Add the handle to your IndexChanged Event varRowIndex = dgvEmbroList.CurrentCell.RowIndex AddHandler editingComboBox.SelectedIndexChanged, AddressOf editingComboBox_SelectedIndexChanged End If 'Prevent this event from firing twice, as is normally the case. RemoveHandler dgvEmbroList.EditingControlShowing, AddressOf dgvEmbroList_EditingControlShowing End Sub Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) 'Get the editing control Dim editingComboBox As ComboBox = TryCast(sender, ComboBox) If editingComboBox Is Nothing Then Exit Sub 'Show your Message Boxes If editingComboBox.Text = "Part" Then Dim dlgEnterQty As New dlgEnterQty dlgEnterQty.varStockCode = dgvEmbroList.Rows(varRowIndex).Cells("Stock Code").Value & "-" & dgvEmbroList.Rows(varRowIndex).Cells("Size").Value dlgEnterQty.varOutStd = dgvEmbroList.Rows(varRowIndex).Cells("Qty OutStd").Value Dim result As DialogResult = dlgEnterQty.ShowDialog(Me) If result = Windows.Forms.DialogResult.OK Then dgvEmbroList.Rows(varRowIndex).Cells("Qty Embro").Value = dlgEnterQty.EnterQty dgvEmbroList.Columns("Qty Embro").Visible = True dgvEmbroList.Width = 679 ElseIf result = Windows.Forms.DialogResult.Cancel Then Exit Sub End If Else dgvEmbroList.Rows(varRowIndex).Cells("Qty Embro").Value = dgvEmbroList.Rows(varRowIndex).Cells("Qty OutStd").Value End If End Sub