Solved

Hiding Rows in DataGridView

Posted on 2008-10-20
4
1,859 Views
Last Modified: 2011-10-03
Hi, I'm using VB 2005, WinForms. I have a DataGridView on one of my Forms that contains a set of records. For example purposes in this question, lets assume the records in my DataGridView are similar to the ones below:

Item Name          Type          
Hammer                 A                
Bolt Cutter             A
Screw Driver          A
Electric Drill            B
Electric Saw           B
Hand Saw              A

As you can see all the hand tools are of type "A" and all the electric tools are of type "B".

How can I programatically hide either type?  Let say I wanted to show my user only the hand tools, how do I hide the electric tools?  

I don't want to "removed" them from the DataGridView, because I want to show them at a later time. I simply want to hide them perhaps by using a button click or something similar.

Thanks,
Fulano
0
Comment
Question by:Mr_Fulano
[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
4 Comments
 
LVL 4

Accepted Solution

by:
jlj1527 earned 500 total points
ID: 22764973
You can set Visible property of Rows to False.
Example :
For i as Integer = 0 To yourDataGridView.RowCount - 1
    If yourDataGridView.Rows(i).Cells("Type").ToString() = "B" Then
       yourDataGridView.Rows(i).Visible = False
    End Iif
Next
0
 

Author Comment

by:Mr_Fulano
ID: 22773665
Hi jlj1527, I thnk that may work well...thank you very much!

Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 22773720
Hi jlj1527, one quick followup question...I had to change ".ToSotring()" to "Value" otherwise it would not give me the proper value of the cell, but now I get the error message below"

For i as Integer = 0 To yourDataGridView.RowCount - 1
   If yourDataGridView.Rows(i).Cells("Type").Value = "B" Then  <<<< Changed!
      yourDataGridView.Rows(i).Visible = False
   End If
Next

ERROR MESSAGE:

Additional information: Row associated with the currency manager's position
cannot be made invisible.


What is the "currency manager's position" and how do I fix this...?

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 22773840
Nevermind...I figured it out. You need to add:

>> yourDataGridView.CurrentCell = Nothing <<

For i as Integer = 0 To yourDataGridView.RowCount - 1
   If yourDataGridView.Rows(i).Cells("Type").Value = "B" Then  <<<< Changed!
      yourDataGridView.CurrentCell = Nothing
      yourDataGridView.Rows(i).Visible = False
   End If
Next

Thanks again,
Fulano
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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