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.
 
You can group control by putting them in their own container, for example a Groupbox or Panel, see Containers section in Toolbox.
 
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
 
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
 
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
 
Back
Top