user3382038
user3382038

Reputation: 7

Distinguish between DataGridViewButtonColumn and DataGridViewTextColumn cell click event

I have 4 column in datagridview control,in which 2nd column is the datagridviewtext column whereas 3rd & 4th column are datagridviewbutton column. How to fire different event for datagridviewbutton click and different event for datagridviewtext column as it comes both in datagirdview cellcontent click. or anyother way to find button or text click inside datagridview cell content click.

Upvotes: 0

Views: 458

Answers (1)

etaiso
etaiso

Reputation: 2746

One way to do that, in CellContentClick event, is to check the cell type, like this:

if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() == typeof(DataGridViewButtonCell)
{
    // handle button cell click
}
else if (dataGridView1[e.ColumnIndex, e.RowIndex].GetType() == typeof(DataGridViewTextBoxCell)
{
    // handle textbox cell click
}

And same for other cell types.

Upvotes: 1

Related Questions