Search code examples
c#datagridviewdatagridviewcolumn

How to get Column Header Text on double click


I want to take the ColumnHeader Text of the ColumnHeader that has been double clicked. This is what I've gotten so far. It doesn't work. Can anyone help?

private void dataGridView1_ColumnHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        string TheDate = dataGridView1.SelectedColumns.ToString();
        MessageBox.Show(TheDate);
    }

Solution

  • You can get index of column through DataGridViewCellMouseEventArgs object e and use to get the HeaderText

    string text = dataGridView1.Columns[e.ColumnIndex].HeaderText;