Question Group controls?

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
I am trying to group various controls (of the same type, eg. labels together, buttons together, etc. ) on a form using a tag or a name of some sort so I can identify all those that belong to tag 'A' and those in tag 'B'. In the end I will have on a form a number of labels grouped as tag 'A' and some labels as tag 'B' so I can change their visible properties on/off. Any clues? Thanks for the replies.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,431
Location
Norway
Programming Experience
10+
You can group control by putting them in their own container, for example a Groupbox or Panel, see Containers section in Toolbox.
 

picoflop

Well-known member
Joined
Feb 25, 2009
Messages
158
Programming Experience
5-10
Why dont you simply use the "name" of the Controls?

Say you have Buttons (and/or Labels etc) that CONTAIN GrpA in their name (Like "BtnOpenFileGrpA") and others that have GrpB in their name.
No you could select the required ones with LINQ like this:
VB.NET:
Dim ctl = From p As Control In Me.Controls Select p Where p.Name.StartsWith("Btn") AndAlso p.Name.Contains("GrpA")
        For Each c As Control In ctl
            c.Visible = False
            ' or whatever you want
        Next
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I am trying to group various controls (of the same type, eg. labels together, buttons together, etc. ) on a form using a tag or a name of some sort so I can identify all those that belong to tag 'A' and those in tag 'B'. In the end I will have on a form a number of labels grouped as tag 'A' and some labels as tag 'B' so I can change their visible properties on/off. Any clues? Thanks for the replies.
You could always use the Tag property :D
 

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
thanks for all the replies.. found the solution with some help.
Here is it for future reference:
It selects whatever control in the form wherever that lies in(groupboxes, panels, etc).
Dim ctl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.
Do Until ctl Is Nothing
If TypeOf ctl Is Label And ctl.Name.StartsWith("GB") Then
ctl.Visible = False
End If
'Use ctl here.
ctl = Me.GetNextControl(ctl, True) 'Get the next control in the tab order.
Loop
 
Top Bottom