473,382 Members | 1,396 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,382 software developers and data experts.

How to apply propertygrid's attributes to existing object?

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
4 5082
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicolas | last post by:
I want to display in my application a PropertyGrid showing only the "Appearance" of a control (ie. textBox) so the user can change it. Bare with me, I'm new in csharp. Where do I go from:...
2
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only...
1
by: ANDRES BECERRA | last post by:
Herfried K. Wagner was kind enough to point me to the PropertyGrid control http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformspropertygridclasstopic.asp I have found a few...
4
by: Bernie Yaeger | last post by:
How can I set the browsableattributes of the control that has been selected (selectedobject) by the propertygrid? Here's what I'm after - I want to open a form with a propertygrid in it. The...
5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
0
by: Marco Segurini | last post by:
HI, my form contains a combobox and a propertygrid control. At each string of the combobox is associated an object. When I select a string of the combobox the associated object is selected in...
0
by: movieknight | last post by:
Hi, I have a class which I am feeding to the propertygrid, and I am exposing a Mesh object from my class for the propertygrid to display. I want the propertygrid to show the values (when you...
4
by: phcmi | last post by:
I have a PropertyGrid question. My task is to replace a legacy dialog box presentation with a modern one. The dialog itself allows the user to set configuration settings in our application, so...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.