How to unselect all cells from a DataGridView?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bluberiman
    New Member
    • May 2010
    • 6

    #1

    How to unselect all cells from a DataGridView?

    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 :

    Code:
    dataGridView1.ClearSelection();
    and

    Code:
    foreach(DataGridViewRow row in dataGridView1.Rows)
    {
    dataFridView1.Rows[row.index].selected=false;
    }
    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
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    Maybe it helps to unselect all cells?

    Code:
    foreach (DataGridViewRow row in DGV.Rows) {
      row.Selected = false;
      foreach (DataGridViewCell cell in row.Cells) {
        cell.Selected = false;
      }
    }

    Comment

    • Bluberiman
      New Member
      • May 2010
      • 6

      #3
      I just tried it and the top leftmost cell is still highlighted. I can't figure why.
      Last edited by Bluberiman; Jun 1 '10, 04:09 PM. Reason: typo

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

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

        Comment

        • Bluberiman
          New Member
          • May 2010
          • 6

          #5
          It seems to be working so far.

          Thanks!

          Comment

          Working...