473,382 Members | 1,353 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.

TypeConverters

Hello everyone,

I'm a VB6 junkie at heart, but in light of the way the winds are blowing
I thought it about time I get to grips with C#... As a way in then, I
have set myself the task of creating a grid control. So far, things are
going swimingly...

One problem though - my grid control makes use of a TStyle class,
representing the style of the cells (background, foreground etc) of the
grid for different conditions. Since a "style" is really just a list of
related (compound) properties, I thought I might have a look at this
"TypeConverter" stuff so as to present these properties in an organised
manner in the properties window...

Here's my class as it currently stands:

public class TGridStyleConverter : System.ComponentModel.TypeConverter
{
public TGridStyleConverter():base()
{
}

public override bool
GetPropertiesSupported(System.ComponentModel.IType DescriptorContext
context) {
//return base.GetPropertiesSupported(context);
return true;

}

public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context,
object value, Attribute[] attributes)
{
PropertyDescriptorCollection props;
if( attributes == null )
props = TypeDescriptor.GetProperties(value);
else
props = TypeDescriptor.GetProperties(value,
attributes);

PropertyDescriptor[] propArray = new
PropertyDescriptor[props.Count]; for(int
i=0;
i<props.Count; i++) {
// Create a new PropertyDescriptor from the
old one, with
// a CategoryAttribute matching the name of
the type.
propArray[i] =
TypeDescriptor.CreateProperty(props[i].ComponentType, props[i], new
CategoryAttribute(props[i].PropertyType.Name)); }
return new PropertyDescriptorCollection( propArray
);

//return TypeDescriptor.GetProperties(typeof
(TGridStyle));
}
}

This code is largely taken from the Microsoft example on MSDN.
I've implemented it on my Grid's properties using the following
attributes:

[ImmutableObject(true),
Category("Styling"),
Description("The default style applied to lines in the
grid."),
TypeConverter(typeof(TGridStyleConverter)),

DesignerSerializationVisibility
(DesignerSerializationVisibility.Content)]

When I look at my Grid's style propeties though, rather than getting a
list of compound properties for the styles, I just get an empty text box
that I can't put anything in (in the properties window...)

Anyone able to offer me any pointers?

Martin.
May 25 '06 #1
0 998

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

Similar topics

3
by: Dave Girvitz | last post by:
I have a PropertyGrid (Windows Forms App) based component that uses TypeConverters to generate ranges of acceptable values for properties. The idea was that I could download the key/value pairs...
0
by: Eric Eggermann | last post by:
I use a PropertyGrid in my UI. I had a property of type image, and the prop grid popped up an open file dialog where the user could select an image, then display a tiny thumbnail of it, along with...
0
by: Adam Dockter | last post by:
Does anyone know if it is possible to have both a DesignTimeVisible(false) and a TypeConverter attribute together. public class ExplorerGroup : Component {...} I use this object in a...
0
by: S.Sigal | last post by:
Hello: I've been trying to 'organize' the layout of my larger controls by moving variables into instances of subclasses...but it just dawned on me that I might be opening a real can of worms due...
3
by: Rick Voight | last post by:
Hi. I have a class N with two properties. I have a control C with a property of type N. I wrote a Type Converter class for class N that can convert a string into N (splits the string and assign...
0
by: ljlevend | last post by:
I need to create TypeConverters for the floating type drawing structures (i.e., PointF, SizeF and RectangleF) that behave exactly as their integer couterparts (e.g., System.Drawing.PointConverter)....
0
by: herpers | last post by:
Hi, I'm writing a control with a lot of properties, that are not directly supported by the propertygrid. I can work around this by writing typeconverters, that do the job for me, but I think for...
0
by: Shell | last post by:
Hi, So here's my story. I have an enum that's defined so: public enum AccountKind { Savings = 0, Current = 1, }
3
by: =?Utf-8?B?R3JlZyBDbGFyaw==?= | last post by:
I have an object which I present to the user through a propertyGrid. With many of the properties (many of which are objects themselves) I have implemented my own TypeConverters; many of these...
0
by: Sparky74 | last post by:
I have a number of Int32 properties that I want to display in a PropertyGrid control. The problem I have is that I want to be able to bypass the framework's default validation. If you have an Int32...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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:
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: 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...

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.