I have a DataGridView
with 5 columns.
The Cells of Columns 1 and 5 are ComboBoxes.
I have a function that runs whenever I change any of these ComboBoxes.
Now, for the function to run properly, I have to get which Column does the ComboBox that I have edited belongs to.
Its like, when I change the ComboBox that belongs to Column 1, Function 1
runs.
When I change the ComboBox that belongs to Column 5, Function 2
runs.
Or
DataGridView.CurrentCell.ColumnIndex
Then if your have a predefined columns in DataGridView
(for example name of column will be DataGridView_ComboBoxOne
) and don't want hardcode a compare of indexes
You can use like this:
Select case DataGridView.CurrentCell.ColumnIndex
Case DataGridView_ComboBoxOne.Index
Function1()
Case DataGridView_ComboBoxTwo.Index
Function2()
Case Else
'Update of other columns
End Select
Dim columnIndex as Integer
columnIndex = e.ColumnIndex
This is the straight way to get the column index without using current cell. Use it under DataGridView1_ColumnHeaderMouseClick.
Ah silly me,
DataGridView.CurrentCellAddress.X 'Column
DataGridView.CurrentCellAddress.Y 'Row
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With