but_je_rycha
but_je_rycha

Reputation: 9

How to check column name of clicked cell in datagridview

I have dataGridView and CellDoubleClick event.

I need to do some actions when cell is clicked two times but it must be cell in a column with a specific name. I don't have any idea how to check column name.

P.S. dataGridView must have SelectionMode = FullRowSelect

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        if ( /*check column name*/ )
        {
            // actions
        }
    }

Upvotes: 0

Views: 2074

Answers (1)

Dren
Dren

Reputation: 1099

You can get it from the event

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
    
        string columnName = this.dataGridViewName.Columns[e.ColumnIndex].Name;
        if ( columnName )
        {
            // actions
        }
    }

you can get the index with

 int columnIndex = dGVTransGrid.CurrentCell.ColumnIndex;

Upvotes: 4

Related Questions