S
S.Sigal
Hello:
I've seen code in some books for databinding that handles attaching Attributes
to
Properties during runtime...which is very close (but no cigar) to what I am
looking for...
The code in the book was basically the following:
override protected void PreFilterProperties(IDictionary properties) {
base.PreFilterProperties(properties);
PropertyDescriptor prop = (PropertyDescriptor)properties["DataSource"];
if(prop!=null) {
System.ComponentModel.AttributeCollection runtimeAttributes =
prop.Attributes;
// make a copy of the original attributes but make room for one extra
attribute
//ie the TypeConverter attribute
Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1];
runtimeAttributes.CopyTo(attrs, 0);
attrs[runtimeAttributes.Count] = new
TypeConverterAttribute(typeof(DataSourceConverter));
prop = TypeDescriptor.CreateProperty(this.GetType(), "DataSource",
typeof(string),attrs);
properties["DataSource"] = prop;
}...
Although this is not what I want -- it intrigues me, because one of the things I
wish to do is change the Designer attribute on a Control on the fly --
specifically, to change a Control's ControlDesigner attribute from standard
ControlDesigner to ReadWriteDesigner --- and back again -- to get around the
limitations that are in the IDE...
Only problem is that I don't see anywhere in the Framwork where to SET
attributes... I can read them, and can append to them as above snippet shows:
System.ComponentModel.AttributeCollection attrsExist = o.GetType().Attributes;
It's just the last line that I am missing....Something that would look like:
o.SetAttributes(attrsNew);
Any hope for this to succeed? I mean ANY way? Even if a nightmare....?
Thank you ,
Sky
I've seen code in some books for databinding that handles attaching Attributes
to
Properties during runtime...which is very close (but no cigar) to what I am
looking for...
The code in the book was basically the following:
override protected void PreFilterProperties(IDictionary properties) {
base.PreFilterProperties(properties);
PropertyDescriptor prop = (PropertyDescriptor)properties["DataSource"];
if(prop!=null) {
System.ComponentModel.AttributeCollection runtimeAttributes =
prop.Attributes;
// make a copy of the original attributes but make room for one extra
attribute
//ie the TypeConverter attribute
Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1];
runtimeAttributes.CopyTo(attrs, 0);
attrs[runtimeAttributes.Count] = new
TypeConverterAttribute(typeof(DataSourceConverter));
prop = TypeDescriptor.CreateProperty(this.GetType(), "DataSource",
typeof(string),attrs);
properties["DataSource"] = prop;
}...
Although this is not what I want -- it intrigues me, because one of the things I
wish to do is change the Designer attribute on a Control on the fly --
specifically, to change a Control's ControlDesigner attribute from standard
ControlDesigner to ReadWriteDesigner --- and back again -- to get around the
limitations that are in the IDE...
Only problem is that I don't see anywhere in the Framwork where to SET
attributes... I can read them, and can append to them as above snippet shows:
System.ComponentModel.AttributeCollection attrsExist = o.GetType().Attributes;
It's just the last line that I am missing....Something that would look like:
o.SetAttributes(attrsNew);
Any hope for this to succeed? I mean ANY way? Even if a nightmare....?
Thank you ,
Sky