Solved

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

Posted on 2010-11-23
6
341 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 74

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 74

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now