473,396 Members | 2,090 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,396 software developers and data experts.

TypeOf question

hello, i would like to write a function that takes a webcontrol type as a
parameter and returns an array of controls based on the type

some thing like:

GetAllControls(typeof(system.web.ui.webcontrols.te xtbox)) 'returns textboxes
GetAllControls(typeof(system.web.ui.webcontrols.dr opdownlist)) 'returns
dropdowns
GetAllControls(typeof(system.web.ui.webcontrols)) 'returns everything

however i can not find the proper way to write the signature

Public sub GetAllControls(Byref tType as ??????????)

thanks
Aug 10 '06 #1
2 1312
Something like:

Public Function GetAllControlsOfType(ByVal type As Type, ByVal parent As
Control) As ArrayList
Dim arr As New ArrayList()
For Each c As Control In parent.Controls
If (c.HasControls) Then
arr.AddRange(GetAllControlsOfType(type, c))
End If
If (c.GetType().IsAssignableFrom(type)) Then
arr.Add(c)
End If
Next
Return arr
End Function

should work..

You can call it via:

GetAllControlsOfType(new TextBox().GetType(), Page)

If you don't like the "new TextBox().GetType()", you cna get the type via:

Type.GetType("System.Web.UI.WebControls.TextBox, System.Web", true, true)

but you'll need to specify the full assembly name (token, culture,
version..) since System.Web sits in the GAC..

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Muckeypuck" <Bl**********@blah.blahwrote in message
news:E3JCg.51$xk3.13@dukeread07...
hello, i would like to write a function that takes a webcontrol type as a
parameter and returns an array of controls based on the type

some thing like:

GetAllControls(typeof(system.web.ui.webcontrols.te xtbox)) 'returns
textboxes
GetAllControls(typeof(system.web.ui.webcontrols.dr opdownlist)) 'returns
dropdowns
GetAllControls(typeof(system.web.ui.webcontrols)) 'returns everything

however i can not find the proper way to write the signature

Public sub GetAllControls(Byref tType as ??????????)

thanks


Aug 10 '06 #2
Thanks Karl

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
Something like:

Public Function GetAllControlsOfType(ByVal type As Type, ByVal parent As
Control) As ArrayList
Dim arr As New ArrayList()
For Each c As Control In parent.Controls
If (c.HasControls) Then
arr.AddRange(GetAllControlsOfType(type, c))
End If
If (c.GetType().IsAssignableFrom(type)) Then
arr.Add(c)
End If
Next
Return arr
End Function

should work..

You can call it via:

GetAllControlsOfType(new TextBox().GetType(), Page)

If you don't like the "new TextBox().GetType()", you cna get the type via:

Type.GetType("System.Web.UI.WebControls.TextBox, System.Web", true, true)

but you'll need to specify the full assembly name (token, culture,
version..) since System.Web sits in the GAC..

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Muckeypuck" <Bl**********@blah.blahwrote in message
news:E3JCg.51$xk3.13@dukeread07...
>hello, i would like to write a function that takes a webcontrol type as a
parameter and returns an array of controls based on the type

some thing like:

GetAllControls(typeof(system.web.ui.webcontrols.t extbox)) 'returns
textboxes
GetAllControls(typeof(system.web.ui.webcontrols.d ropdownlist)) 'returns
dropdowns
GetAllControls(typeof(system.web.ui.webcontrols )) 'returns everything

however i can not find the proper way to write the signature

Public sub GetAllControls(Byref tType as ??????????)

thanks



Aug 11 '06 #3

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

Similar topics

3
by: James Marshall | last post by:
I need to detect the type of an object, more than just "object" as typeof gives us. I'm writing a general handler that accepts a variety of objects and properties, and acts accordingly depending...
4
by: pn | last post by:
Hi when comparing a Type object to several built-in types, do you recommend to use Type.GetTypeCode() instead of typeof() ? Is there a BIG performance difference Example if (type ==...
6
by: MM | last post by:
Very basic question: string mystr how do you test if it is a string? Something like if (mystr.GetType() == "System.String") <<< but this doesn't work.
11
by: Jason Kendall | last post by:
Why doesn't the new "IsNot" operator work in conjunction with 'Typeof'?
4
by: EManning | last post by:
Using A2003. I've got an option group that has a number of check boxes. I have coding to clear the option group if the user wishes to cancel their choice. This coding also clears the rest of the...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
11
by: Einar Værnes | last post by:
Hi. I am trying to programatically decide which type a new object should have, but the typeof-function is apparently not the answer, as the following code will not compile. class...
20
by: rkk | last post by:
Hi, Is there an equivalent typeof macro/method to determine the type of a variable in runtime & most importantly that works well with most known C compilers? gcc compiler supports typeof()...
6
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i'm trying to modify some code to accept an enum then use reflection to fill a dropdown list. If i name the type directly, replace enm with the real name of the enum it works, no suprise. Question...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.