Karthik
Karthik

Reputation: 318

How to get the index of the selected column in data grid view in windows forms using c#?

How to get the index of the selected column in DataGridView ? (windows forms using c#)

I have a DataGridView with 30 columns in it.Now the task is,when the user clicks any of the 30 columns header,the selected column index is shown in message box.I want help to do this..

Upvotes: 0

Views: 1456

Answers (1)

DeveloperX
DeveloperX

Reputation: 4683

write your code in ColumnHeaderMouseClick

   private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        MessageBox.Show(e.ColumnIndex.ToString());
    }

Upvotes: 1

Related Questions