473,394 Members | 1,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Get ALL controls on a Form

Hi,

Is there actually a way to get ALL the Controls on a Form? While using the
ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.

I never found something like that, but it just would be nice in my opinion
:-)

Thanks,

Pieter
Nov 21 '05 #1
6 9787
Hi,
you can use following code snippet.

foreach (Control ctr in this.Controls)
{
if (ctr.HasChildren) // Check for Containder Control
{
//Controls on other control (e.g Panel)
}
}

Hope this will solve your problem

Prasad.
"DraguVaso" wrote:
Hi,

Is there actually a way to get ALL the Controls on a Form? While using the
ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.

I never found something like that, but it just would be nice in my opinion
:-)

Thanks,

Pieter

Nov 21 '05 #2
private ControlCollection res = new ControlCollection();
public void GetControls(Control parent)
{
if (! parent is Form)
{
res.Add(parent);
}

foreach(Control c in parent.Controls)
{
GetControls(c);
}
}

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
Hi,

Is there actually a way to get ALL the Controls on a Form? While using the
ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.

I never found something like that, but it just would be nice in my opinion
:-)

Thanks,

Pieter

Nov 21 '05 #3
On 20/09/2005 DraguVaso wrote:
Hi,

Is there actually a way to get ALL the Controls on a Form? While
using the ControlCollection, it only returns the Controls that are
directly on the Form, not the controls that are on a
(TableLayout)Panel etc.

You could use a recursive procedure.

private sub GetControls(Control ctlParent, ref ArrayList al)
{
al.Add(ctlParent);
foreach(Control ctlChild in ctlParent)
GetControls(ctlChild, ref al);
}

Not tested, my development PC is off at the moment but something like
that should do it. Call it by setting up a new ArrayList and starting
with the Windows Form. If it doesn't recognise the Form as a control
you would need to start with:

private sub GetAllControls()
{
ArrayList al = new ArrayList();
foreach(Control ctl in frmMain)
GetControls(ctl, ref al);
}
--
Jeff Gaines
Nov 21 '05 #4
Pieter
Is there actually a way to get ALL the Controls on a Form? While using the
ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.

Roughly done
\\\
Showall(me)
Private Sub ShowAll(ByVal parentCtr As Control)
For Each ctr As Control In parentCtr.Controls
Console.Write(ctr.name)
ShowAll(ctr)
Next
End Sub
///
I hope this helps,

Cor
Nov 21 '05 #5
Thanks guys, I guess recursion will indeed be the only solution for this. I
think it's kind of weird there isn't a Collection that returns everything on
a form, but so be it, hehe :-)

Pieter

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eA*************@TK2MSFTNGP10.phx.gbl...
Pieter
Is there actually a way to get ALL the Controls on a Form? While using the ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.

Roughly done
\\\
Showall(me)
Private Sub ShowAll(ByVal parentCtr As Control)
For Each ctr As Control In parentCtr.Controls
Console.Write(ctr.name)
ShowAll(ctr)
Next
End Sub
///
I hope this helps,

Cor

Nov 21 '05 #6
"DraguVaso" <pi**********@hotmail.com> schrieb:
Is there actually a way to get ALL the Controls on a Form? While using the
ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.


\\\
Private Sub RecurseControls(ByVal ctr As Control)
Debug.WriteLine(ctr.Name)
If ctr.HasChildren Then
For Each c As Control In ctr.Controls
RecurseControls(c)
Next c
End If
End Sub
..
..
..
RecurseControls(Me)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Robert | last post by:
Hello. I have been trying out the Lebans ToolTip Classes at http://www.lebans.com/tooltip.htm, to display "balloon" style help tips in a form. The classes I am using are located at...
7
by: Saintor | last post by:
What I do now is I put a value in the tag property, and using the form_current event, I run through all controls properties until the ones with the required tag value are met. Sound OK in theory,...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
3
by: Roger | last post by:
Hi In a Windows forms application I have 2 forms A and B; Form B inherits from form A. Form A is never displayed and its only purpose is to be inherited from and therefore contains mostly...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.