Mr_Fulano
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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).C ells("Type ").Value = "B" Then <<<< Changed!
yourDataGridView.Rows(i).V isible = 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
For i as Integer = 0 To yourDataGridView.RowCount - 1
If yourDataGridView.Rows(i).C
yourDataGridView.Rows(i).V
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
ASKER
Nevermind...I figured it out. You need to add:
>> yourDataGridView.CurrentCe ll = Nothing <<
For i as Integer = 0 To yourDataGridView.RowCount - 1
If yourDataGridView.Rows(i).C ells("Type ").Value = "B" Then <<<< Changed!
yourDataGridView.CurrentCe ll = Nothing
yourDataGridView.Rows(i).V isible = False
End If
Next
Thanks again,
Fulano
>> yourDataGridView.CurrentCe
For i as Integer = 0 To yourDataGridView.RowCount - 1
If yourDataGridView.Rows(i).C
yourDataGridView.CurrentCe
yourDataGridView.Rows(i).V
End If
Next
Thanks again,
Fulano
ASKER
Fulano