Reputation: 633
private void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow r in dgv.Rows) r.Visible = false;
}
This code works, but also works if ColumnHeaders (not only cells) is doubleClicked ?
I want to run it only if a cell is doubleClicked.
CellDoubleClick should mean CellDoubleClick and not HeaderDoubleClick.
Upvotes: 10
Views: 11183
Reputation: 11201
Not the cleanest way to do but you can achieve it like this
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (((System.Windows.Forms.DataGridView)(sender)).CurrentCell != null)
{
//Do what you want here................
}
}
Upvotes: 1
Reputation: 3298
private void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
if (e.RowIndex != -1) {
//do work
}
}
Upvotes: 23
Reputation: 7200
You could check if e.RowIndex
is -1, which means the event happened on a header row.
Upvotes: 3
Reputation: 19601
You can use DataGridViewCellEventArgs.RowIndex
to check if the header is clicked or any cell from the rows is clicked.
Upvotes: 2