Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-11-23
6
Medium Priority
?
358 Views
Last Modified: 2012-06-27
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
Comment
Question by:jigdog
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34200132
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34200140
>>  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
 
LVL 32

Expert Comment

by:Erick37
ID: 34200153
Use the Grid's ClearSelection() method
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

by:jigdog
ID: 34200242
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
 

Accepted Solution

by:
jigdog earned 0 total points
ID: 34200291
THIS DID IT:


YourGridView.CurrentCell = Nothing
0
 

Author Closing Comment

by:jigdog
ID: 34224661
Solved!
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question