473,804 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop ALL Properties

I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length located
at MyTextBox.Prope rties.MaxLength - instead of the dotnet textbox which is
MyTextBox.MaxLe ngth. If I loop a built in dotnet control, it finds the
property no problem. But looping through the 3rd party control,
Properties.MaxL ength does not get listed. I was hoping to find how it names
it using reflection, so I could use GetValue and SetValue to dyanmically set
values of controls without knowing their type until runtime. How can I gain
access to loop ALL the properties of a control?

Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties ()
Console.WriteLi ne("{0} = {1}", pp.Name, pp.GetValue(ctl , Nothing))
Next

Oct 28 '08 #1
10 1871
Hi Derek,

Did I get it right that MyTextBox.Prope rties is sort of your own array of
'properties', like dictionary? If so, that how it relates to 'real properties',
'native' for a class?

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
i

Oct 28 '08 #2
You should be looping recursively.

"Derek Hart" <de********@yah oo.comwrote in message
news:eI******** ******@TK2MSFTN GP03.phx.gbl...
>I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length located
at MyTextBox.Prope rties.MaxLength - instead of the dotnet textbox which is
MyTextBox.MaxL ength. If I loop a built in dotnet control, it finds the
property no problem. But looping through the 3rd party control,
Properties.Max Length does not get listed. I was hoping to find how it names
it using reflection, so I could use GetValue and SetValue to dyanmically
set values of controls without knowing their type until runtime. How can I
gain access to loop ALL the properties of a control?

Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties ()
Console.WriteLi ne("{0} = {1}", pp.Name, pp.GetValue(ctl , Nothing))
Next


Oct 28 '08 #3
3rd Party Developer Express textbox control. It has many properties. Can't
figure out how to loop and get all of them.

"Alex Meleta" <am*****@gmail. comwrote in message
news:df******** *************** **@news.microso ft.com...
Hi Derek,

Did I get it right that MyTextBox.Prope rties is sort of your own array of
'properties', like dictionary? If so, that how it relates to 'real
properties', 'native' for a class?

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
>i


Oct 28 '08 #4
Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.co mwrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
You should be looping recursively.

"Derek Hart" <de********@yah oo.comwrote in message
news:eI******** ******@TK2MSFTN GP03.phx.gbl...
>>I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length
located at MyTextBox.Prope rties.MaxLength - instead of the dotnet textbox
which is MyTextBox.MaxLe ngth. If I loop a built in dotnet control, it
finds the property no problem. But looping through the 3rd party control,
Properties.Ma xLength does not get listed. I was hoping to find how it
names it using reflection, so I could use GetValue and SetValue to
dyanmically set values of controls without knowing their type until
runtime. How can I gain access to loop ALL the properties of a control?

Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties ()
Console.WriteLi ne("{0} = {1}", pp.Name, pp.GetValue(ctl , Nothing))
Next



Oct 28 '08 #5
This is taken straight from
http://msdn.microsoft.com/en-us/libr...pertyinfo.aspx.
It's not actually recursive - you have to repeat it for each member type of
interest.

I created a picture box with some scroll bars, which is similar (I think) to
your custom controls, and sent the output to a multiline text box.

Imports System.Reflecti on
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim t As Type = PictureBox1.Get Type
For Each pp As PropertyInfo In t.GetProperties ()
listproperties( pp)
Next
End Sub
Sub listproperties( ByVal pp As PropertyInfo)
Display(indent, pp.Name)
indent += 1
For Each mi As MethodInfo In pp.GetAccessors
ListAccessors(m i)
Next
indent -= 1
End Sub
Sub ListAccessors(B yVal mi As MethodInfo)
Display(indent, mi.Name)
End Sub
Sub Display(ByVal indent As Int32, ByVal s As String)
textBox1.Text += New String(" "c, indent * 2)
textBox1.Text += s & vbCrLf
End Sub
End Class

"Derek Hart" <de********@yah oo.comwrote in message
news:ud******** ******@TK2MSFTN GP04.phx.gbl...
Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.co mwrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
>You should be looping recursively.

"Derek Hart" <de********@yah oo.comwrote in message
news:eI******* *******@TK2MSFT NGP03.phx.gbl.. .
>>>I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length
located at MyTextBox.Prope rties.MaxLength - instead of the dotnet textbox
which is MyTextBox.MaxLe ngth. If I loop a built in dotnet control, it
finds the property no problem. But looping through the 3rd party control,
Properties.M axLength does not get listed. I was hoping to find how it
names it using reflection, so I could use GetValue and SetValue to
dyanmicall y set values of controls without knowing their type until
runtime. How can I gain access to loop ALL the properties of a control?

Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties ()
Console.WriteLi ne("{0} = {1}", pp.Name, pp.GetValue(ctl , Nothing))
Next



Oct 28 '08 #6
More on the right track, but I cannot seem to get to all the properties. In
the dev express controls, on a textboxedit control, in the property sheet,
there is a property called Properties. I expand that and see a MaxLength
property. So the property would be textbox1.proper ties.MaxLength - cannot
seem to loop through and get the names of all the properties, so I can find
how this one is named, and use it at runtime to set values to it, because I
will not know the type of control until runtime. And I don't want to convert
the control because there are too many controls to do this for. So if the
property exists, I want to do a setvalue on it. Any ideas on how to find all
properties?

"James Hahn" <jh***@yahoo.co mwrote in message
news:O3******** ******@TK2MSFTN GP03.phx.gbl...
This is taken straight from
http://msdn.microsoft.com/en-us/libr...pertyinfo.aspx.
It's not actually recursive - you have to repeat it for each member type
of interest.

I created a picture box with some scroll bars, which is similar (I think)
to your custom controls, and sent the output to a multiline text box.

Imports System.Reflecti on
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim t As Type = PictureBox1.Get Type
For Each pp As PropertyInfo In t.GetProperties ()
listproperties( pp)
Next
End Sub
Sub listproperties( ByVal pp As PropertyInfo)
Display(indent, pp.Name)
indent += 1
For Each mi As MethodInfo In pp.GetAccessors
ListAccessors(m i)
Next
indent -= 1
End Sub
Sub ListAccessors(B yVal mi As MethodInfo)
Display(indent, mi.Name)
End Sub
Sub Display(ByVal indent As Int32, ByVal s As String)
textBox1.Text += New String(" "c, indent * 2)
textBox1.Text += s & vbCrLf
End Sub
End Class

"Derek Hart" <de********@yah oo.comwrote in message
news:ud******** ******@TK2MSFTN GP04.phx.gbl...
>Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.co mwrote in message
news:%2******* ********@TK2MSF TNGP06.phx.gbl. ..
>>You should be looping recursively.

"Derek Hart" <de********@yah oo.comwrote in message
news:eI****** ********@TK2MSF TNGP03.phx.gbl. ..
I am going in circles trying to loop through properties on 3rd party
controls. For example, I have a textbox that has its maximum length
located at MyTextBox.Prope rties.MaxLength - instead of the dotnet
textbox which is MyTextBox.MaxLe ngth. If I loop a built in dotnet
control, it finds the property no problem. But looping through the 3rd
party control, Properties.MaxL ength does not get listed. I was hoping to
find how it names it using reflection, so I could use GetValue and
SetValue to dyanmically set values of controls without knowing their
type until runtime. How can I gain access to loop ALL the properties of
a control?

Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties ()
Console.WriteLi ne("{0} = {1}", pp.Name, pp.GetValue(ctl , Nothing))
Next



Oct 28 '08 #7
I don't think that .Properties and .Properties.Max Length can both be
properties. How are these members defined within the class?

"Derek Hart" <de********@yah oo.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
More on the right track, but I cannot seem to get to all the properties.
In the dev express controls, on a textboxedit control, in the property
sheet, there is a property called Properties. I expand that and see a
MaxLength property. So the property would be
textbox1.proper ties.MaxLength - cannot seem to loop through and get the
names of all the properties, so I can find how this one is named, and use
it at runtime to set values to it, because I will not know the type of
control until runtime. And I don't want to convert the control because
there are too many controls to do this for. So if the property exists, I
want to do a setvalue on it. Any ideas on how to find all properties?

"James Hahn" <jh***@yahoo.co mwrote in message
news:O3******** ******@TK2MSFTN GP03.phx.gbl...
>This is taken straight from
http://msdn.microsoft.com/en-us/libr...pertyinfo.aspx.
It's not actually recursive - you have to repeat it for each member type
of interest.

I created a picture box with some scroll bars, which is similar (I think)
to your custom controls, and sent the output to a multiline text box.

Imports System.Reflecti on
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
Dim t As Type = PictureBox1.Get Type
For Each pp As PropertyInfo In t.GetProperties ()
listproperties (pp)
Next
End Sub
Sub listproperties( ByVal pp As PropertyInfo)
Display(indent , pp.Name)
indent += 1
For Each mi As MethodInfo In pp.GetAccessors
ListAccessors( mi)
Next
indent -= 1
End Sub
Sub ListAccessors(B yVal mi As MethodInfo)
Display(indent , mi.Name)
End Sub
Sub Display(ByVal indent As Int32, ByVal s As String)
textBox1.Tex t += New String(" "c, indent * 2)
textBox1.Tex t += s & vbCrLf
End Sub
End Class

"Derek Hart" <de********@yah oo.comwrote in message
news:ud******* *******@TK2MSFT NGP04.phx.gbl.. .
>>Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.co mwrote in message
news:%2****** *********@TK2MS FTNGP06.phx.gbl ...
You should be looping recursively.

"Derek Hart" <de********@yah oo.comwrote in message
news:eI***** *********@TK2MS FTNGP03.phx.gbl ...
>I am going in circles trying to loop through properties on 3rd party
>controls . For example, I have a textbox that has its maximum length
>located at MyTextBox.Prope rties.MaxLength - instead of the dotnet
>textbox which is MyTextBox.MaxLe ngth. If I loop a built in dotnet
>control, it finds the property no problem. But looping through the 3rd
>party control, Properties.MaxL ength does not get listed. I was hoping
>to find how it names it using reflection, so I could use GetValue and
>SetValue to dyanmically set values of controls without knowing their
>type until runtime. How can I gain access to loop ALL the properties of
>a control?
>
Dim t As Type = ctl.GetType
For Each pp As PropertyInfo In t.GetProperties ()
Console.WriteLi ne("{0} = {1}", pp.Name, pp.GetValue(ctl , Nothing))
Next
>
>
>
>
>

Oct 28 '08 #8
"James Hahn" <jh***@yahoo.co mwrote in message
news:uo******** ******@TK2MSFTN GP06.phx.gbl...
>I don't think that .Properties and .Properties.Max Length can both be
properties.
Why not? The Properties property probably just returns a class, which itself
has properties.
Oct 28 '08 #9
That's why I believe recursion should work. But I can't see a way to create
a propertyinfo from a property type. If I could do that, then it would solve
the problem. Perhaps I should have said "Reflection apparently doesn't
support both Properties and Properties.Maxl ength as properties of the same
object" (which is the way that the user thinks of them). Some additional
process is required to get access to the properties of a property.

"Jeff Johnson" <i.***@enough.s pamwrote in message
news:ev******** ******@TK2MSFTN GP02.phx.gbl...
"James Hahn" <jh***@yahoo.co mwrote in message
news:uo******** ******@TK2MSFTN GP06.phx.gbl...
>>I don't think that .Properties and .Properties.Max Length can both be
properties.

Why not? The Properties property probably just returns a class, which
itself has properties.
Oct 28 '08 #10

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

Similar topics

1
11951
by: trenchmouth | last post by:
Does anybody know how I can loop through all the properties in a class I have created? Can I use Me to refer to the properties? I'm using VB6. Many thanks.
6
2873
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and loop through all the forms in a database and pull information about the form (controls and properties). We would need to do the same in our VB.NET project; loop through the project and get the web form's control and property information...
2
1780
by: sparks | last post by:
I was going to loop thru the tables and change some properties. 10 <<<<<< prp.value --prp.name = Type False <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type True <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type True <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type True <<<<prp.value --prp.name = allow zero length 4 <<<<<< prp.value...
0
1610
by: Martin | last post by:
Hi, Can anybody please tell me (or point me to documentation on) how to loop through all AD properties of a user. The code I have so far is below. Now if I know the property name I can retrieve it, for eample to retrieve "DisplayName" I would just say. de.Properties.Value
3
1319
by: jcrouse | last post by:
I am trying trying to loop through some label controls and setting some properties for the labels I'm looping through. Currently I am addressing the labels one at a time with IF...Then logic, like this: If lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then lblP1JoyUp.Top = 10
15
1574
by: James Black | last post by:
If you go to http://dante.acomp.usf.edu/HomeworkAssistant/index.php you will see my code. Type in: s = a + b and hit tab, and you will see the extra words. How do I remove these? Here is a snippet of my code: var myvalue = targ.value;
10
2965
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a generic list of business objects. I'm able to see that the type is the correct one in the debugger. However when I try to traverse the list using the type I can't compile. The same type variable I've verified as being passed
10
1733
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the dotnet textbox which is MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the property no problem. But looping through the 3rd party control, Properties.MaxLength does not get listed. I was hoping to find how it names it using...
3
1650
by: BL3WC | last post by:
Hi, I encountered an error "Object not supporting this properties or method" while trying to set a checkbox value to 'True" in a loop. The VBA code I use is as follow: Set a value to intcount (say set intcount to 2) ME("FieldName" & intcount).Properties.Value = True increment intcount by 1 and loop back to set another checkbox value to True base on some conditions.
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.