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

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.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 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.WriteLine("{0} = {1}", pp.Name, pp.GetValue(ctl, Nothing))
Next

Oct 28 '08 #1
10 1826
Hi Derek,

Did I get it right that MyTextBox.Properties 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********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.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.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 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.WriteLine("{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.microsoft.co m...
Hi Derek,

Did I get it right that MyTextBox.Properties 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.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
You should be looping recursively.

"Derek Hart" <de********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.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.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 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.WriteLine("{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.Reflection
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As Type = PictureBox1.GetType
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(ByVal 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********@yahoo.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>You should be looping recursively.

"Derek Hart" <de********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.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.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 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.WriteLine("{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.properties.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.comwrote in message
news:O3**************@TK2MSFTNGP03.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.Reflection
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As Type = PictureBox1.GetType
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(ByVal 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********@yahoo.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>>You should be looping recursively.

"Derek Hart" <de********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.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.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 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.WriteLine("{0} = {1}", pp.Name, pp.GetValue(ctl, Nothing))
Next



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

"Derek Hart" <de********@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.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.properties.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.comwrote in message
news:O3**************@TK2MSFTNGP03.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.Reflection
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As Type = PictureBox1.GetType
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(ByVal 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********@yahoo.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>>Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
You should be looping recursively.

"Derek Hart" <de********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.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.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 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.WriteLine("{0} = {1}", pp.Name, pp.GetValue(ctl, Nothing))
Next
>
>
>
>
>

Oct 28 '08 #8
"James Hahn" <jh***@yahoo.comwrote in message
news:uo**************@TK2MSFTNGP06.phx.gbl...
>I don't think that .Properties and .Properties.MaxLength 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.Maxlength 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.spamwrote in message
news:ev**************@TK2MSFTNGP02.phx.gbl...
"James Hahn" <jh***@yahoo.comwrote in message
news:uo**************@TK2MSFTNGP06.phx.gbl...
>>I don't think that .Properties and .Properties.MaxLength can both be
properties.

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

I also use in my apps the dx controls. I do in my loop over all controls a
simple "select case" to difference beetween the differnt controltypes and
then i set the properties.

That works pretty good.
HTH Wolfgang
"Derek Hart" <de********@yahoo.comschrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP05.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.properties.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.comwrote in message
news:O3**************@TK2MSFTNGP03.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.Reflection
Public Class Form1
Dim indent As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As Type = PictureBox1.GetType
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(ByVal 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********@yahoo.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>>Do you have a sample of how I would do that from my code below?

"James Hahn" <jh***@yahoo.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
You should be looping recursively.

"Derek Hart" <de********@yahoo.comwrote in message
news:eI**************@TK2MSFTNGP03.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.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 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.WriteLine("{0} = {1}", pp.Name, pp.GetValue(ctl, Nothing))
Next
>
>
>
>
>

Oct 29 '08 #11

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

Similar topics

1
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
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...
2
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...
0
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...
3
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...
15
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...
10
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...
10
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.