• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

.NET GridView SelectedRows - Set it to Nothing (No selection)

I am performing a text search in the cells of the GridView.  As I enumerate the cells, I set the row visibility to false.  However, the 'selectedrow' can never be set to false.  How do I make SelectedRows empty.  Nada.  And this is not a webcontrol, where you can set SelectedIndex to -1.
0
jigdog
Asked:
jigdog
  • 3
  • 2
1 Solution
 
käµfm³d 👽Commented:
Are you using a foreach? If so, you cannot modify the collection referenced in the foreach. You could use a while loop:
while (this.dataGridView1.SelectedRows.Count > 0)
{
    foreach (DataGridViewCell cell in this.dataGridView1.SelectedRows[0].Cells)
    {
        // search cell
    }

    this.dataGridView1.SelectedRows[0].Selected = false;
}

Open in new window

0
 
käµfm³d 👽Commented:
>>  you cannot modify the collection referenced in the foreach

I should state this as, "you cannot remove/add elements to the collection referenced in the foreach within the foreach itself."
0
 
Erick37Commented:
Use the Grid's ClearSelection() method
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jigdogAuthor Commented:
It is still not effective.  Try this:  if you enumerate all rows in a datagrid, setting them to Visible = False ... the first row (or whichever row has the carat beside it)  will still show.  How do we prevent this?
0
 
jigdogAuthor Commented:
THIS DID IT:


YourGridView.CurrentCell = Nothing
0
 
jigdogAuthor Commented:
Solved!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now