From: Mr. X. on
Also - propertyGrid may be a good solution, if I knew how to resolve by
propertyGrid all of the properties of selected control.

"Mr. X." <nospam(a)nospam_please.com> wrote in message
news:#zTPHYLELHA.5472(a)TK2MSFTNGP04.phx.gbl...
> No.
> (I have answered the previous thread).
> As your advise, I did getProperties & getCustomAttributes either :
> prs = ... getProperties
> for I = 0 to prs.count - 1
> dim prop = prs(j)
> dim atts = prop.GetCustomAttributes
> for each att in atts ... ' as your code below.
>
> ... but I have reach the inner loop only when :specialAtt.Visibility was
> hidden.
> (And I don't get all of the properties, that are seen on the designer :
> properties view).
>
> It doesn't meter whether I use a serializable object or using Reflection,
> but, I see that serializable isn't possible for Panel, I.e, and I didn't
> understand reflection (I don't know if I should use getProperties method,
> or getFields method -
> both don't return the same fields' count as the property grid does on
> design time).
>
> Thanks :)
>
> "Armin Zingler" <az.nospam(a)freenet.de> wrote in message
> news:Ok6v3LLELHA.5736(a)TK2MSFTNGP02.phx.gbl...
>> Am 20.06.2010 21:23, schrieb Mr. X.:
>>> When PropertyGrid is connected to a selectedObject :
>>> How can I run through all of the object properties, which are seen on
>>> the
>>> propertyGrid, and get the name + value ?
>>> (What is behind PropertyGrid ?)
>>
>> What is the problem with the solution you already have? Doesn't
>> it work?
>>
>>
>> --
>> Armin
>
From: Armin Zingler on
Am 20.06.2010 22:20, schrieb Mr. X.:
> No.
> (I have answered the previous thread).
> As your advise, I did getProperties & getCustomAttributes either :
> prs = ... getProperties
> for I = 0 to prs.count - 1
> dim prop = prs(j)
> dim atts = prop.GetCustomAttributes
> for each att in atts ... ' as your code below.
>
> .... but I have reach the inner loop only when :specialAtt.Visibility was
> hidden.
> (And I don't get all of the properties, that are seen on the designer :
> properties view).
>
> It doesn't meter whether I use a serializable object or using Reflection,
> but, I see that serializable isn't possible for Panel, I.e, and I didn't
> understand reflection (I don't know if I should use getProperties method, or
> getFields method -
> both don't return the same fields' count as the property grid does on design
> time).

Your question in this thread is how to run through the properties of an object.
You can do it with reflection, and you know how to do it. I still don't understand
what you can not do with it.

A Panel is not serializable. You have to take it as it is, i.e. you have to
write your own code to write the property values to wherever you want.

'GetProperties' returns the properties and 'GetField' gets the fields. :-)
I think the names say it. As you are doing these kinds of tasks, I think you
already know the difference because these are basic terms in OOP:

http://msdn.microsoft.com/en-us/library/exe76ct6(VS.90).aspx

The VB documentation is sometimes more made for dummies (or "beginners") than structrued
very well. Probably therefore, fields are described as part of the property explanation:

http://msdn.microsoft.com/en-us/library/8yx6f707(VS.90).aspx


--
Armin
From: Armin Zingler on
Am 20.06.2010 22:36, schrieb Mr. X.:
> Also - propertyGrid may be a good solution, if I knew how to resolve by
> propertyGrid all of the properties of selected control.

I can also only look in the documentation of the PropertyGrid
to find out which properties are shown by the property grid.
It says that public properites that don't have the BrowsableAttribute(False)
attached, are displayed.


Don't forget that properties can be inherited or not, can have
different access modifiers (public, private, etc) and they can be
static or instance members. You can pass the appropriate System.Reflection.BindingFlags
value(s) to the GetProperties method to get only the required
properties.


The code below returns 28 properties. I don't know if it's the 28 you've mentioned
in the other reply:

Dim t = GetType(PictureBox)
Dim tBrowsable = GetType(System.ComponentModel.BrowsableAttribute)

For Each prop In t.GetProperties(Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance)
Dim atts = prop.GetCustomAttributes(tBrowsable, False)
If atts.Length = 0 Then
Debug.Print(prop.Name)
End If
Next


--
Armin
From: Mr. X. on
Great.
Now I just have to check this.
(Where did you find that documentation ? I want to search this code either).
How can I check this (checking the public and attribute. Is my code correct
?)
Still there are some problems.
Specifically for panel, the properties: UseWaitCursor, autoSize,
autoSizeMode have the attribute : browsableAttribute, and are shown on
design time.
Also there are extra properties, that logically are considered : Site,
displayRectangle.

As the following code:
=================
prs =
myControl.GetType().GetProperties(BindingFlags.Public Or
BindingFlags.Instance)
k = 0
foundBA = False ' flag for finding the attribute
For j = 0 To prs.Count - 1
foundBA = False ' flag for finding the attribute
For Each att In prs(j).GetCustomAttributes(False)
If TypeOf att Is
System.ComponentModel.BrowsableAttribute Then
foundBA = True
End If
Next
If Not foundBA Then
k += 1
end if
next
msgBox ("k = " & k) ' now k = 34, where it should be 35
!!!


"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:OUvlmsLELHA.5472(a)TK2MSFTNGP04.phx.gbl...
> Am 20.06.2010 22:36, schrieb Mr. X.:
>> Also - propertyGrid may be a good solution, if I knew how to resolve by
>> propertyGrid all of the properties of selected control.
>
> I can also only look in the documentation of the PropertyGrid
> to find out which properties are shown by the property grid.
> It says that public properites that don't have the
> BrowsableAttribute(False)
> attached, are displayed.
>
>
> Don't forget that properties can be inherited or not, can have
> different access modifiers (public, private, etc) and they can be
> static or instance members. You can pass the appropriate
> System.Reflection.BindingFlags
> value(s) to the GetProperties method to get only the required
> properties.
>
>
> The code below returns 28 properties. I don't know if it's the 28 you've
> mentioned
> in the other reply:
>
> Dim t = GetType(PictureBox)
> Dim tBrowsable = GetType(System.ComponentModel.BrowsableAttribute)
>
> For Each prop In t.GetProperties(Reflection.BindingFlags.Public Or
> Reflection.BindingFlags.Instance)
> Dim atts = prop.GetCustomAttributes(tBrowsable, False)
> If atts.Length = 0 Then
> Debug.Print(prop.Name)
> End If
> Next
>
>
> --
> Armin

From: Armin Zingler on
Am 21.06.2010 00:04, schrieb Mr. X.:
> Great.
> Now I just have to check this.
> (Where did you find that documentation ? I want to search this code either).
> How can I check this (checking the public and attribute. Is my code correct
> ?)

"Remarks" section, 5th paragraph:
http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid(VS.90).aspx

> Still there are some problems.
> Specifically for panel, the properties: UseWaitCursor, autoSize,
> autoSizeMode have the attribute : browsableAttribute, and are shown on
> design time.

My fault. I did not code what I said. :-) Only checking whether the BrowsableAttribute
is not attached is not sufficient. The property is also included if the attribute's
Browsable is True:

If atts.Length = 0 _
OrElse DirectCast(atts(0), System.ComponentModel.BrowsableAttribute).Browsable Then

Debug.Print(prop.Name)
End If

This results in 37 properties.


> Also there are extra properties, that logically are considered : Site,
> displayRectangle.
> [...]
> msgBox ("k = " & k) ' now k = 34, where it should be 35

If 35 + 2 (Site + displayRectangle) = 37 = correct then it should be the right result now.


--
Armin