2

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);
    }
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
Josh
  • 115
  • 1
  • 3
  • 17

2 Answers2

2

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

string text = dataGridView1.Columns[e.ColumnIndex].HeaderText;
Adil
  • 146,340
  • 25
  • 209
  • 204
2

Try that:

if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
    string theDate = dataGridView1.Columns[e.ColumnIndex].Name;
}
Orkun Bekar
  • 1,447
  • 1
  • 15
  • 36