Josh
Josh

Reputation: 115

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);
    }

Upvotes: 2

Views: 2451

Answers (2)

Orkun Bekar
Orkun Bekar

Reputation: 1441

Try that:

if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
    string theDate = dataGridView1.Columns[e.ColumnIndex].Name;
}

Upvotes: 2

Adil
Adil

Reputation: 148110

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

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

Upvotes: 2

Related Questions