Solved

Hiding Rows in DataGridView

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

12 Experts available now in Live!

Get 1:1 Help Now