Link to home
Start Free TrialLog in
Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America

asked on

Hiding Rows in DataGridView

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
ASKER CERTIFIED SOLUTION
Avatar of jlj1527
jlj1527
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Fulano

ASKER

Hi jlj1527, I thnk that may work well...thank you very much!

Fulano
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
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