![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Loop ALL Properties You should be looping recursively. "Derek Hart" <derekmhart@xxxxxx> wrote in message news:eI87BIKOJHA.1172@xxxxxx Quote: >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 > > > > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Loop ALL Properties Do you have a sample of how I would do that from my code below? "James Hahn" <jhahn@xxxxxx> wrote in message news:%23BLj6FLOJHA.648@xxxxxx Quote: > You should be looping recursively. > > "Derek Hart" <derekmhart@xxxxxx> wrote in message > news:eI87BIKOJHA.1172@xxxxxx Quote: >>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 >> >> >> >> >> |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Loop ALL Properties 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" <derekmhart@xxxxxx> wrote in message news:udjvSXLOJHA.1960@xxxxxx Quote: > Do you have a sample of how I would do that from my code below? > > "James Hahn" <jhahn@xxxxxx> wrote in message > news:%23BLj6FLOJHA.648@xxxxxx Quote: >> You should be looping recursively. >> >> "Derek Hart" <derekmhart@xxxxxx> wrote in message >> news:eI87BIKOJHA.1172@xxxxxx Quote: >>>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 >>> >>> >>> >>> >>> > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Loop ALL Properties 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" <jhahn@xxxxxx> wrote in message news:O3W2h3LOJHA.2912@xxxxxx Quote: > 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" <derekmhart@xxxxxx> wrote in message > news:udjvSXLOJHA.1960@xxxxxx Quote: >> Do you have a sample of how I would do that from my code below? >> >> "James Hahn" <jhahn@xxxxxx> wrote in message >> news:%23BLj6FLOJHA.648@xxxxxx Quote: >>> You should be looping recursively. >>> >>> "Derek Hart" <derekmhart@xxxxxx> wrote in message >>> news:eI87BIKOJHA.1172@xxxxxx >>>>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 >>>> >>>> >>>> >>>> >>>> >>> >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Loop ALL Properties I don't think that .Properties and .Properties.MaxLength can both be properties. How are these members defined within the class? "Derek Hart" <derekmhart@xxxxxx> wrote in message news:%234ilosMOJHA.1148@xxxxxx Quote: > 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" <jhahn@xxxxxx> wrote in message > news:O3W2h3LOJHA.2912@xxxxxx Quote: >> 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" <derekmhart@xxxxxx> wrote in message >> news:udjvSXLOJHA.1960@xxxxxx Quote: >>> Do you have a sample of how I would do that from my code below? >>> >>> "James Hahn" <jhahn@xxxxxx> wrote in message >>> news:%23BLj6FLOJHA.648@xxxxxx >>>> You should be looping recursively. >>>> >>>> "Derek Hart" <derekmhart@xxxxxx> wrote in message >>>> news:eI87BIKOJHA.1172@xxxxxx >>>>>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 >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>> >>> > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Loop ALL Properties "James Hahn" <jhahn@xxxxxx> wrote in message news:uonwwHNOJHA.1744@xxxxxx Quote: >I don't think that .Properties and .Properties.MaxLength can both be >properties. has properties. |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Loop ALL Properties 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.get@xxxxxx> wrote in message news:evmk$NQOJHA.4088@xxxxxx Quote: > "James Hahn" <jhahn@xxxxxx> wrote in message > news:uonwwHNOJHA.1744@xxxxxx > Quote: >>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. > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| I might be out of the loop but... | General Discussion | |||
| help with for next loop | VB Script | |||
| Modifying OEM properties listed in system properties | Vista installation & setup | |||
| Do Loop | Vista General | |||
| Cannot access properties in "local area connection properties" win | Vista networking & sharing | |||