How to find column name with column index in DataGridView?

Nagendra Kumar picture Nagendra Kumar · Sep 29, 2010 · Viewed 91.2k times · Source

I want to find column name in DataGridView. I have column index. How can I find it.

dGVTransGrid.CurrentCell.ColumnIndex: I want it's column name.

Plz help.

Thanks.

Answer

Jon Skeet picture Jon Skeet · Sep 29, 2010

There may be a better way, but why don't you just ask the DataGridView what the column with that index is called?

int columnIndex = dGVTransGrid.CurrentCell.ColumnIndex;
string columnName = dGVTransGrid.Columns[columnIndex].Name;