473,769 Members | 5,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change the display name of a object's property in PropertyGrid

Hi group,

I have a class like this:
class Person
{
public uint Age
{
get{...}
set{...}
}
}

Thus a PropertyGrid displays the Person.Age property as "Age".
But I want to display it in chinese, but not the english word "Age", and I
don't want to change this class's definition .
Is it possible?

Thank you very much!
Nov 16 '05 #1
2 14323
Today I Find that this feature is included by .NET Framewoke 2.0.
By "DisplayNam e" Attribute:

[DisplayName("My Age")]
public uint Age
{
get{...}
set{...}
}

It seems that it is impossible in .NET Framewoke 1.1 ...?
"X.W." <ip*****@gmail. com> дϢ news:cv******** ***@mail.cn99.c om...
Hi group,

I have a class like this:
class Person
{
public uint Age
{
get{...}
set{...}
}
}

Thus a PropertyGrid displays the Person.Age property as "Age".
But I want to display it in chinese, but not the english word "Age", and I
don't want to change this class's definition .
Is it possible?

Thank you very much!

Nov 16 '05 #2
It is possible.

The steps I followed are:

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

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

3. Create a class that implements the ICustomTypeDesc riptor interface.
Implement the GetProperties functions to return a
PropertyDescrip torCollection 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 ICustomTypeDesc riptor
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.

The following article helped me immensely:

http://www.codeproject.com/cs/miscct...opertygrid.asp

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1546
by: Craig L | last post by:
How do I use a variable value within the document object's property? That is, if I have: document.profile_form.firstname.value=fname; How do I make it more generic, like this: desired=fieldname document.profile_form.desired.value=fname;
1
1775
by: windandwaves | last post by:
Hi Folk I am working with the TYPE property. I want to change that from 2 (byte) to 4 (long integer) for a field that already contains tons of data. How can I do that? The help reads: For a Field or Property object, this property is read/write until the object is appended to a collection or to another object, after which it's
0
1180
by: Peder Y | last post by:
I'm using a propertygrid in my application. However, displaying names of properties like "iOrderNum" should be displayed like "Order Number". Now, we all know that "Order Number" is not a valid variable or property name. So how can I tweak the propertygrid to show my custom name for a property? - Peder -
2
1881
by: Andrzej Kaczmarczyk | last post by:
Hi, I have following problem: (warning, quite long post with lots of code) I have an object of a known type like this. class MyClass { public int Property1; public string Property2; }
0
1493
by: Sebastiao Pereira Filho | last post by:
When I bind a server control to a repeater it renders one copy of this control for each item in the datasource collection. By doing this it changes the name of the dynamically created controls, to ensure each name is unique. My problem is that the repeater control has a proprietary pattern to gererate this names and I'd like to use a pattern that's standard for my applications (and to my client-side scripts). I got to partially change...
10
2166
by: Hugh | last post by:
Hi there, An existing solution is used to create a new solution. It is easy to change the names of individual forms and modules. However, how to change the name of project folder? Thanks in advance for your help. Hugh
1
1650
by: tomjbr.32022025 | last post by:
I have started looking at the nhibernate framework, but do not really like the string based API which makes it impossible to use automatic refactoring of a property name without the risk of getting problems where the property has been refered to as a string... Therefore I am wondering if it would be even theoretically possible to improve such a framework with stronger typing, to avoid the usage of strings. For example, consider this...
0
2261
by: not_a_commie | last post by:
I have a base class with a collection of objects. I want to change the display name of that in my descendant classes. I tried this line: base.Nodes.GetType().GetCustomAttributes(typeof(DisplayNameAttribute), true).SetValue("Gates", 0); but it's wrong. I don't need the type. I need the propertyInfo (I guess) ? I'd like to just make my own property in the descendant classes and
9
1943
by: =?Utf-8?B?VmljdG9y?= | last post by:
Is it a way to discover, at the run time, the name of a property of an object? In other words is it possible to create a method GetPropertyName, that takes a property of an object and returns the name of that property? So: string name = GetPropertyName(int.MaxValue); // returns “MaxValue” string name = GetPropertyName(DateTime.Now); // returns “Now” (Something similar exists to...
0
1721
by: michelqa | last post by:
Hi, Is there any way to display a IHTMLDocument2 object in a propertyGrid?? When trying to do something like the following the property grid is simply blank : using mshtml; //...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.