Show/Hide Multiple Groupboxes in a single form

T1TAN23

Member
Joined
Jun 15, 2006
Messages
9
Location
Austin, TX
Programming Experience
3-5
I am somewhat new to the VB.NET platform so please bare with me if I don't know all the lingo to ask the questions properly.

I have a single form with 5 groupboxes all stacked on top of each other. I set their visability with Menu clicks. When A user clicks on a menu Item I set that groupbox to be visible and hide all the rest, simple enough. SO here is my problem...

Before the user can start the application (clicking on the start button) I run a check from my module to ensure that all the neccesary information has been entered into each of the groupboxes if not then I popup a msgbox and let the user know what is missing and then show the realted groupbox, hide the rest and set focus on the item that is missing. The part I am having so much trouble with is trying to do this from my module.

How do I loop though all the groupboxes and turn on the one I need to and turn off the rest from with in my moudule.

Thanks,
~Trent~
 
So here is teh method I am trying to use taht doesn't seem to be working

VB.NET:
Private FormItems As New Form1
 
Public Sub ShowHideGroupBox(ByVal GroupBoxToShow As GroupBox)
For Each C As Control In FormItems.Controls
If TypeOf C Is GroupBox Then
If C.Name = GroupBoxToShow.ToString Then
GroupBoxToShow.Visible = True
Else
C.Visible = False
End If
End If
Next C
End Sub

This all resides inside my module. I hope this helps to shed some light on my problem.

Thanks,
~Trent~
 
I will not give you a working code but hints:
You should read about the difference between ByVal and ByRef


In your code "Private FormItems As New Form1"
you are creating a new Instance of Form1, so you are changing the Visible properties of a new instance of Form1.

In your function
Public Sub ShowHideGroupBox(ByVal GroupBoxToShow As GroupBox)

The parameter ByVal GroupBoxToShow will just pass the value not the reference that you can change the property of.

ANd finally in the LOC
If C.Name = GroupBoxToShow.ToString Then

compare .Name to .Name

.ToString will have other information also.

HTH
 
Back
Top