Solved

Hiding Rows in DataGridView

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 35
vb.net 2 37
Visual Studio 2013 Shortcut (VB) 4 34
Want to create a userform that looks like the image provided 10 44
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now