简体   繁体   中英

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.

PS dataGridView must have SelectionMode = FullRowSelect

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM