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.