By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

How to apply propertygrid's attributes to existing object?

P: n/a
I have assigned an existing object to propertygrid.selectedobject property.
But I only want some of the object's properties not browsable and/or
readonly. How can I do that?

I'm trying to find information about propertygrid but most of the
information seems to be for VS2003.
Oct 2 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Oct 2, 5:07 pm, Peter <Pe...@discussions.microsoft.comwrote:
I have assigned an existing object to propertygrid.selectedobject property.
But I only want some of the object's properties not browsable and/or
readonly. How can I do that?

I'm trying to find information about propertygrid but most of the
information seems to be for VS2003.
Check out the BrowsableAttribute class. You can decorate your
properties and methods with it to indicate which ones you want visible
in the property grid.

Another way would be to create an adapter object that contains an
instance of the "real" object and only expose the properties that you
need.

Chris

Oct 3 '07 #2

P: n/a
Hi Chris,

I think the BrowsableAttribute class is only useful if I have control on the
class coding. The object assigned to propertygrid is an object returned by
a .NET method so I have no direct way to change the attribute. Based on
what I have found so far, I think it is possible to change the attribute of
the existing object using reflection but I need to learn reflection first if
that is the only way.

Can you elaborate about the adapter object way?

"Chris Dunaway" wrote:
On Oct 2, 5:07 pm, Peter <Pe...@discussions.microsoft.comwrote:
I have assigned an existing object to propertygrid.selectedobject property.
But I only want some of the object's properties not browsable and/or
readonly. How can I do that?

I'm trying to find information about propertygrid but most of the
information seems to be for VS2003.

Check out the BrowsableAttribute class. You can decorate your
properties and methods with it to indicate which ones you want visible
in the property grid.

Another way would be to create an adapter object that contains an
instance of the "real" object and only expose the properties that you
need.

Chris

Oct 3 '07 #3

P: n/a
Hello Peter,

On the PropertyGrid Resource List (http://
www.propertygridresourcelist.com), you will find a lot of
informations. One of the links of the list points to a Microsoft
article where the TypeDescriptionProvider (new in .net 2.0) is
explained. From the article:

"This allows you to write a separate class that implements
ICustomTypeDescriptor and then to register this class as the provider
of descriptions for other types".

This is here: http://msdn.microsoft.com/msdnmag/is...05/NETMatters/

I hope this helps.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://
www.visualhint.com/index.php/fieldpackeditor)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
On Oct 3, 2:11 pm, Peter <Pe...@discussions.microsoft.comwrote:
Hi Chris,

I think the BrowsableAttribute class is only useful if I have control on the
class coding. The object assigned topropertygridis an object returned by
a .NET method so I have no direct way to change the attribute. Based on
what I have found so far, I think it is possible to change the attribute of
the existing object using reflection but I need to learn reflection first if
that is the only way.

Can you elaborate about the adapter object way?

"Chris Dunaway" wrote:
On Oct 2, 5:07 pm, Peter <Pe...@discussions.microsoft.comwrote:
I have assigned an existing object topropertygrid.selectedobject property.
But I only want some of the object's properties not browsable and/or
readonly. How can I do that?
I'm trying to find information aboutpropertygridbut most of the
information seems to be for VS2003.
Check out the BrowsableAttribute class. You can decorate your
properties and methods with it to indicate which ones you want visible
in the property grid.
Another way would be to create an adapter object that contains an
instance of the "real" object and only expose the properties that you
need.
Chris

Oct 4 '07 #4

P: n/a
On Oct 3, 1:11 pm, Peter <Pe...@discussions.microsoft.comwrote:
Hi Chris,

I think the BrowsableAttribute class is only useful if I have control on the
class coding. The object assigned to propertygrid is an object returned by
a .NET method so I have no direct way to change the attribute. Based on
what I have found so far, I think it is possible to change the attribute of
the existing object using reflection but I need to learn reflection first if
that is the only way.

Can you elaborate about the adapter object way?
I simply meant create another class that acts as a container to the
class you want to limit the properties for and then only expose the
properties you want:

Public Class AdapaterClass

'classToLimit has lots of properties, but we only want some of
them
'visible in the PropertyGrid

Private _instance As classToLimit

Public Sub New(object As classToLimit )
_instance = object
End Sub

Public Property Property1() As String
Get
Return _instance.Property1
End Get
Set
_instance.Property1 = Value
End Set
End Property

Public Property Property2() As String
Get
Return _instance.Property2
End Get
Set
_instance.Property2 = Value
End Set
End Property

<Browsable(False)_
Public ReadOnly Property Instance() As classToLimit
Get
Return _instance
End Get
End Property

End Class

Then you add an instance of the AdapterClass to the PropertyGrid.

I think VisualHint's suggestion is probably the way to go, but this
method, at least, is easy.

Chris

Oct 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.