Solved

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

Posted on 2010-11-23
6
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can Selenium do Load Testing? 2 61
EF5 How do I stop pre-compiled views? 8 57
Difference between Leaflet and MapBox? 5 47
VB.NET Parsing UDP Bytes 15 38
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

752 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