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.
private void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
if (e.RowIndex != -1) {
//do work
}
}
You could check if e.RowIndex
is -1, which means the event happened on a header row.
You can use DataGridViewCellEventArgs.RowIndex
to check if the header is clicked or any cell from the rows is clicked.
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................
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With