PropertyGrid and property names

C

Chris Dunaway

Consider the following simple class:

Public Class SomeClass
Private _AnInteger As Integer

Public Property AnInteger As Integer
Get
Return _AnInteger
End Get
Set(Value As Integer)
_AnInteger = Value
End Set
End Property
End Class


If I use the PropertyGrid to display an object of this type, the property
is displayed as "AnInteger". I would like to make the property appear
with alternate text for the property name, but still map to the right
property.

For example, I would like the property in the grid to read "My Integer
Value" (note that I've included spaces) instead of "AnInteger".

Is there any way to make the property grid do this? Or does anyone know of
a control that could do this?

Perhaps what I'm looking for is an attribute that could be applied to the
property to change the display of the grid. But I could not find any.

Thanks,


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
C

Chris Dunaway

On Mon, 16 Aug 2004 10:02:44 -0500, Chris Dunaway wrote:

For the benefit of those seeking an answer to this question, I found the
solution.

The steps I followed are:

1. Create an attribute class (inherited from Attribute) for the
DisplayName

2. Create a class that inherits from PropertyDescriptor and override the
DisplayName property to return what you want to appear in the PropertyGrid

3. Create a class that implements the ICustomTypeDescriptor interface.
Implement the GetProperties functions to return a
PropertyDescriptorCollection with instances of the class defined in step 2.

4. Finally, create the class you want to display in the PropertyGrid and
make sure it inherits from the class defined in step 3 above. You can also
combine steps 3 and 4 by by just implementing the ICustomTypeDescriptor
interface in your class.

When you assign an instance of that class to the SelectedObject property of
the PropertyGrid, the grid will show your custom property names.

If anyone wants the code that I used, I will be happy to let them have it.

The following article helped me immensely:

http://www.codeproject.com/cs/miscctrl/globalizedpropertygrid.asp

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top