0

I am using Friend WithEvents PersonName As DataGridViewComboBoxColumn as a column in DataGridView and PersonName DataSoucre is bounded to a database. I would like for when the ComboBox Selection is changed it uses that value to query my database Business Object to find the right value then I want to set the value from the query to the column to the right of the one with the ComboBox which is named Colum3.

But am not use how to access each individual event handler for the ComboBox cell, I tried dgvTable.CellBeginEdit but it triggers too early.

Private Sub dgvTable_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles dgvTable.CellBeginEdit
    If e.RowIndex <> -1 And e.ColumnIndex <> -1 Then
        dgvTable.Rows(e.RowIndex).Cells("Colum3").Value = dgvTable.Rows(e.RowIndex).Cells(e.ColumnIndex).Value & "Somevalue from my databse"
    End If
End Sub
Dev
  • 1,780
  • 3
  • 18
  • 46
  • Use the [CellValueChangedEvent](https://learn.microsoft.com/de-de/dotnet/api/system.windows.forms.datagridview.cellvaluechanged?view=net-5.0). Also if you want to update your gridview from the database you have to update the DataSource since it will not happen autoamtically. – Alex B. Nov 20 '20 at 15:04
  • That´s not the whole truth, look at this [answer](https://stackoverflow.com/questions/5652957/what-event-catches-a-change-of-value-in-a-combobox-in-a-datagridviewcell) how to get the changed value of the combobox – Alex B. Nov 20 '20 at 15:08
  • The [CellBeginEdit](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.cellbeginedit?view=net-5.0) event occurs when edit mode starts for the selected cell. So I don't think this event is the one you should use. Take a look at the links @AlexB. posted. You can also edit your question and give more details, eg. what your grid looks like, and an example of what you're trying to achive. – Han Nov 20 '20 at 19:56

0 Answers0