473,746 Members | 2,703 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 14320
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
1774
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
1880
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
1491
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
1649
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
1942
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
1712
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
8974
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8800
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
9349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8227
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 project—planning, coding, testing, and deployment—without 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
6060
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
4575
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2199
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.