Hi,
I have a property grid in which i am showing some expandable properties.
My requirement is to have further expandable properties of expanded properties.
Is it possible to further expand an already expanded property?
Plz Reply.......
| | Jogesh Grover Wednesday, July 11, 2007 12:28 PM | here is a quick proof of concept. I modified some code that I had previously so the sub-expandable property is not functional, but you get the idea...
Code Snippet
string testString="aaa|bbb";
....
Code Snippet
[TypeConverter(typeof(TestStringConverter))] public string TestString { get { return testString; } set { testString = value; } }
...
Code Snippet
class TestStringConverter : TypeConverter { #region Methods public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { if (context != null) {
PropertyDescriptorCollection myCollection = new PropertyDescriptorCollection(null); myCollection.Add(new TestStringDescriptor("one", context)); myCollection.Add(new TestStringDescriptor("two", context, new Attribute[] { new TypeConverterAttribute(typeof(TestStringConverter)) })); return myCollection; } return base.GetProperties(context, value, attributes); } public override bool GetPropertiesSupported(ITypeDescriptorContext context) { if (context != null) { return true; } return base.GetPropertiesSupported(context); } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return false; } #endregion class TestStringDescriptor : SimplePropertyDescriptor { ITypeDescriptorContext fContext; string name;
public TestStringDescriptor(string name, ITypeDescriptorContext context) : base(typeof(string), name, typeof(string)) { fContext = context; this.name = name; } public TestStringDescriptor(string name, ITypeDescriptorContext context, Attribute [] attributes) : base(typeof(string), name, typeof(string), attributes) { fContext = context; this.name = name; }
public override object GetValue(object component) { string[] components = ((string)component).Split('|');
if (name == "one" && components.Length >= 1) return components[0]; if (name == "two" && components.Length >= 2) return components[1]; return ""; } public override void SetValue(object component, object value) { string[] components = ((string)component).Split('|'); string[] newcomponents = new string [2]; for(int i = 0; i<components.Length; i++) { newcomponents[i] = components[i]; } if (name == "one") newcomponents[0] = (string)value; else if (name == "two") newcomponents[1] = (string)value; fContext.PropertyDescriptor.SetValue(fContext.Instance, newcomponents[0] + "|" + newcomponents[1]); ; } } }
| | Rado R Wednesday, July 11, 2007 3:35 PM | Sure, you should be able to have nested expandable properties. Just have appropriate TypeConverters for the sub properties and it should work. If you have custom property descriptors in GetProperties(...), just pass the appropriate TypeConverter attributes to the descriptor constructor.
| | Rado R Wednesday, July 11, 2007 3:16 PM | here is a quick proof of concept. I modified some code that I had previously so the sub-expandable property is not functional, but you get the idea...
Code Snippet
string testString="aaa|bbb";
....
Code Snippet
[TypeConverter(typeof(TestStringConverter))] public string TestString { get { return testString; } set { testString = value; } }
...
Code Snippet
class TestStringConverter : TypeConverter { #region Methods public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { if (context != null) {
PropertyDescriptorCollection myCollection = new PropertyDescriptorCollection(null); myCollection.Add(new TestStringDescriptor("one", context)); myCollection.Add(new TestStringDescriptor("two", context, new Attribute[] { new TypeConverterAttribute(typeof(TestStringConverter)) })); return myCollection; } return base.GetProperties(context, value, attributes); } public override bool GetPropertiesSupported(ITypeDescriptorContext context) { if (context != null) { return true; } return base.GetPropertiesSupported(context); } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return false; } #endregion class TestStringDescriptor : SimplePropertyDescriptor { ITypeDescriptorContext fContext; string name;
public TestStringDescriptor(string name, ITypeDescriptorContext context) : base(typeof(string), name, typeof(string)) { fContext = context; this.name = name; } public TestStringDescriptor(string name, ITypeDescriptorContext context, Attribute [] attributes) : base(typeof(string), name, typeof(string), attributes) { fContext = context; this.name = name; }
public override object GetValue(object component) { string[] components = ((string)component).Split('|');
if (name == "one" && components.Length >= 1) return components[0]; if (name == "two" && components.Length >= 2) return components[1]; return ""; } public override void SetValue(object component, object value) { string[] components = ((string)component).Split('|'); string[] newcomponents = new string [2]; for(int i = 0; i<components.Length; i++) { newcomponents[i] = components[i]; } if (name == "one") newcomponents[0] = (string)value; else if (name == "two") newcomponents[1] = (string)value; fContext.PropertyDescriptor.SetValue(fContext.Instance, newcomponents[0] + "|" + newcomponents[1]); ; } } }
| | Rado R Wednesday, July 11, 2007 3:35 PM |
|