473,408 Members | 2,477 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,408 software developers and data experts.

Property grid and parametrized category descryption.

Hi,

Is it possible to parametrize Property grid category?

I have class:

[DefaultProperty("Name")]
public class Test
{
private string name;

[Category("Misc"),
Description("Name")]
public string Name
{
get
{
return this.name;
}

set
{
this.name = value;
}
}
}

I need to parametrize line where I set category for Name property (
Category(<<my parameter>>) ). I prepare app where I want to change this
string using configuration file for this e.g. xml file where I have
category string in different languages.

--
Best regards,
Klaudiusz
Jan 7 '08 #1
4 2575
I prepare app where I want to change this string using configuration
file for this e.g. xml file where I have category string in
different languages.
Not with CategoryAttribute itself... but IIRC you can subclass it, and
override GetLocalizedString to lookup from your language file
(suggest: resx, since it already handles languages etc).

public class MyCategoryAttribute : CategoryAttribute {
public MyCategoryAttribute(string category) : base(category) { }
protected override string GetLocalizedString(string key) {
return YourLookupHere(key);
}
}

class SomeClass {
[MyCategory("LOOKUP_KEY")]
string SomeProperty {
get { return "abc"; }
}
}
Jan 7 '08 #2
You might want to look at this approach for using the .NET
PropertyGrid. Much simpler and easier to manipulate
at runtime.

http://www.eggheadcafe.com/tutorials...d-control.aspx

--
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web surveys
Free download: http://www.equalssolved.com/default.aspx


"us*************@interia.pl" <dl*@zmyly.plwrote in message
news:fl**********@atlantis.news.tpi.pl...
Hi,

Is it possible to parametrize Property grid category?

I have class:

[DefaultProperty("Name")]
public class Test
{
private string name;

[Category("Misc"),
Description("Name")]
public string Name
{
get
{
return this.name;
}

set
{
this.name = value;
}
}
}

I need to parametrize line where I set category for Name property (
Category(<<my parameter>>) ). I prepare app where I want to change this
string using configuration file for this e.g. xml file where I have
category string in different languages.

--
Best regards,
Klaudiusz
Jan 7 '08 #3
You should have your class implement the ICustomTypeDescriptor
interface, which returns the properties (as well as the attributes
associated with the properties). When the PropertyGrid sees this, it will
query that implementation for the type information, instead of going through
reflection. You can then return the Category attributes with whatever value
you want.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"us*************@interia.pl" <dl*@zmyly.plwrote in message
news:fl**********@atlantis.news.tpi.pl...
Hi,

Is it possible to parametrize Property grid category?

I have class:

[DefaultProperty("Name")]
public class Test
{
private string name;

[Category("Misc"),
Description("Name")]
public string Name
{
get
{
return this.name;
}

set
{
this.name = value;
}
}
}

I need to parametrize line where I set category for Name property (
Category(<<my parameter>>) ). I prepare app where I want to change this
string using configuration file for this e.g. xml file where I have
category string in different languages.

--
Best regards,
Klaudiusz

Jan 7 '08 #4
You should have your class implement the ICustomTypeDescriptor
interface
I'm no stranger to System.ComponentModel, but that seems a little
excessive just for this? Arguably, though, it could be a reasonable
job for a TypeDescriptionProvider (especially if you don't have
control of the class and want to change the attributes to add
localization support to an object that doesn't provide it itself) -
but forcing the class to implement this (non-trivial) interface? Do-
able, I suppose, but arguably not very clean...?

I'm not saying it is the de-facto response, but MS do it via the
"subclass CategoryAttribute" approach... IIRC, SRCategoryAttribute,
XmlCategoryAttribute and a whole bunch of others to meet different
scenarios. There is good support for this, and it is trivial to
implement...

I'm just saying...

Marc
Jan 7 '08 #5

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

Similar topics

2
by: Steve Teeples | last post by:
Someone introduced me to PropertyGrid last night. It is a great feature for what I need. A question though. I noticed that when I assign a "TextBox" control to a property grid the description on...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
1
by: John Kraft | last post by:
Hi all, I'm trying to use a property grid, and what I'm trying to do seems to really elude me. I've been using the property grid for a short period of time, and this is the first thing I...
2
by: Lespaul36 | last post by:
I have a control that I have made that uses a custom class for storage of some of the information. I want it to display in the VS.Net 2003 property grid in the IDE like the Font property does, so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.