How to get the current Column Index while editing a cell in DataGridView using VB.NET

datagridview, vb.net

Solution

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

Problem

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.

Original source