Solved

Hiding Rows in DataGridView

Posted on 2008-10-20
4
1,807 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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