Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unselect all rows in datagridview

I have two datagridviews, and when I click to one of them, I would like to deselect all selection in the second datagridview, I tried this, but nothing works:

firstItemsDataGridView.ClearSelection(); firstItemsDataGridView.CurrentCell = null; 

not working,

firstItemsDataGridView.ClearSelection(); if (firstItemsDataGridView.Rows.Count > 0)     firstItemsDataGridView[1, 0].Selected = true; firstItemsDataGridView.CurrentCell = null; firstItemsDataGridView.ClearSelection(); foreach (DataGridViewRow item in firstItemsDataGridView.Rows) {     item.Selected = false;      foreach (DataGridViewCell itemCell in firstItemsDataGridView.Columns) {         itemCell.Selected = false;     } } 

not working,

firstItemsDataGridView.Rows[0,-1].Selected = true; 

not working too.

I have set selecting mode to full row selection, and I have no idea how to achieve my goal.
thanks a lot!

like image 271
Martin Ch Avatar asked Sep 06 '11 21:09

Martin Ch


People also ask

How to deselect dataGridView row c#?

dataGridView1. ClearSelection(); Should work. Maybe you have code that auto selects rows which is triggered?


1 Answers

dataGridView1.ClearSelection(); 

Should work. Maybe you have code that auto selects rows which is triggered?

like image 150
Mitzi Avatar answered Sep 21 '22 03:09

Mitzi