By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,143 Members | 709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,143 IT Pros & Developers. It's quick & easy.

How to unselect all cells from a DataGridView?

P: 6
Hi,

Here's my problem. I have a dataGridview and everytimes I refresh the date from the database, the top leftmost cell (which is a combobox) is always selected. I found a couples of suggestion while searching for a solution :

Expand|Select|Wrap|Line Numbers
  1. dataGridView1.ClearSelection();
  2.  
and

Expand|Select|Wrap|Line Numbers
  1. foreach(DataGridViewRow row in dataGridView1.Rows)
  2. {
  3. dataFridView1.Rows[row.index].selected=false;
  4. }
  5.  
Even though those solution seems to work for many people, they don't work for me... any idea why? My DGV is bounded but the column aren't autogenerated, I do this myself.

Thanks
Jun 1 '10 #1

✓ answered by Plater

What if you set the .CurrentCell proeprty to null or something?

Share this Question
Share on Google+
4 Replies

Expert 100+
P: 218
Maybe it helps to unselect all cells?

Expand|Select|Wrap|Line Numbers
  1. foreach (DataGridViewRow row in DGV.Rows) {
  2.   row.Selected = false;
  3.   foreach (DataGridViewCell cell in row.Cells) {
  4.     cell.Selected = false;
  5.   }
  6. }
Jun 1 '10 #2

P: 6
I just tried it and the top leftmost cell is still highlighted. I can't figure why.
Jun 1 '10 #3

Plater
Expert 5K+
P: 7,872
What if you set the .CurrentCell proeprty to null or something?
Jun 1 '10 #4

P: 6
It seems to be working so far.

Thanks!
Jun 1 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.