Adding the child controls of a control to a group.

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 1350 Views - Last Post: 21 May 2013 - 04:33 PM Rate Topic: -----

#1 TheSurvivalInstinct   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 13

Adding the child controls of a control to a group.

Posted 21 May 2013 - 12:44 PM

Is there a way to, rather than add an picturebox to a list of controls, add the pixtureboxes it is a Parent of to a list?
Is This A Good Question/Topic? 0
  • +

Replies To: Adding the child controls of a control to a group.

#2 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 01:00 PM

Yes! Loop thru the control collection where they exist.
Was This Post Helpful? 0
  • +
  • -

#3 TheSurvivalInstinct   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 13

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 01:06 PM

Yeah, I just figured it out right after posting... but because I'm new here I can't edit/delete posts :-(
Was This Post Helpful? 0
  • +
  • -

#4 TheSurvivalInstinct   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 13

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 01:15 PM

Is there a way to search the controls of a bunch of objects at once?

I currently have:
        Dim control As Control
        For Each control In PictureBox1.Controls
            GroupedControls.Add(control)
        Next


Rather than copy and paste that for a large number of pictureboxes, is there a way to search for each control in a number of pictureboxes at once?
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 01:31 PM

The only way I could think of off the top of my head is to move back a parent.
For each ctrl as control in Panel1.Controls
   For each otherctrl as control in ctrl.controls
    'do work
   next
next


So you will need to place some insurance that you're working with what you want.

Possibly an If TypeOf ctrl is PictureBox Then

Or limit the For Each to only pull a type in the case that you have mixed controls in the parent.

...


This should loop through the first control in the parent container
Then when it finds a control loop through its controls
Was This Post Helpful? 0
  • +
  • -

#6 TheSurvivalInstinct   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 13

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 01:43 PM

Perfect, thanks so much. I haven't done anything with VB in many years (not since VB 4), so I've been relearning a lot. This place has been really helpful.
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:02 PM

FWIW if you want to loop through all the pictureboxes on the form, and the controls within them:

        For Each pb As PictureBox In Me.Controls.OfType(Of PictureBox)()
            For Each ctl As Control In pb.Controls

            Next
        Next

Of course, it is preferable that all the pictureboxes are contained within another control, to narrow down the search (and keep things organized).
Was This Post Helpful? 0
  • +
  • -

#8 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:11 PM

And yet another way!

Dim myPbs = Me.Controls.OfType(Of PictureBox)()

Was This Post Helpful? 1
  • +
  • -

#9 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 671
  • Joined: 01-October 08

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:19 PM

Me.Controls.OfType(Of PictureBox) does not work if the picture box is in a container.
Was This Post Helpful? 0
  • +
  • -

#10 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:25 PM

Substitute the control collect - come on man!
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:38 PM

View Postdbasnett, on 21 May 2013 - 09:19 PM, said:

Me.Controls.OfType(Of PictureBox) does not work if the picture box is in a container.

Another reason to put all the PictureBoxes of interest in a Panel, assuming this is appropriate for the OP.
Was This Post Helpful? 0
  • +
  • -

#12 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:48 PM

I'm failing to understand this discussion.

If the pictureboxes are in a container then of course me.controls won't work. Why would you try to access controls in the form (Me) when they reside in another container (be it a panel, another picturebox, a groupbox, etc...). And by the way, isn't the form itself a container?

If they are placed inside panel1 then
just take _HAWK_'s code and change it to
Dim myPbs = Me.Panel1.Controls.OfType(Of PictureBox)()

Sorry if I'm missing something here.

EDIT:
I think the gist of what _HAWK_ was trying to show is that in one line of code you could fill an IEnumeral(Of T) with the same objects. I've always used a For Each so I repped it because it had never dawned on me to do this.

This post has been edited by CharlieMay: 21 May 2013 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

#13 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 02:58 PM

Of course, we are speculating, because the OP hasn't stated whether the pictureboxes are directly on the form, or all contained within another control such as a panel. And, yes, the Form itself is a ContainerControl.
Was This Post Helpful? 0
  • +
  • -

#14 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,709
  • Joined: 25-September 09

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 03:04 PM

I just assumed the OP is still working on this

This post has been edited by CharlieMay: 21 May 2013 - 03:05 PM

Was This Post Helpful? 0
  • +
  • -

#15 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Adding the child controls of a control to a group.

Posted 21 May 2013 - 03:11 PM

View PostCharlieMay, on 21 May 2013 - 10:04 PM, said:

I just assumed the OP is still working on this

He has several panels, map4_1, etc., and we don't know whether he wants to navigate all the pictureboxes in this one panel, or across the other panels as well :whatsthat:. The excitement is bearable ;)
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2