How to Use PropertyGrid for Complex Class
-
Suppose I have the following class :
public class A
{
public bool Boolean {get; set;}public List<B> ListOfB {get; set;}
}public class B
{
public String StringValue {get; set;}public List<String> OneList {get; set;}
public List<String> AnotherList {get; set;}
}I want to expose the class A and under it the B class in a propertygrid. I have tried a lot of thing, but no help. May be I am missing something. What I did is as follows :
[DefaultProperty("ListOfB")]
public class A
{
[Browsable(false)]
public bool Boolean {get; set;}[Category("Visuals")]
[Description("YZYZYZ")]
[MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Localizable(true)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Editor(typeof(BListEditor), typeof(UITypeEditor))]
public List<B> ListOfB {get; set;}}
public class B
{
public String StringValue {get; set;}[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[Category("Visuals")]
[Description("XXYZ")]
[MergableProperty(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<String> OneList {get; set;}[Description("PPPWRT")]
[MergableProperty(true)]
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[Category("Visuals")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<String> AnotherList {get; set;}
}public class BListEditor : CollectionEditor
{
public BListEditor()
: base(typeof(List<B> ) )
{ }protected override Type[] CreateNewItemTypes()
{
return new Type[] {typeof(B)};
}protected override object SetItems(object editValue, object[] value)
{
// Cast the context into the expected control type
A settings = (A)Context.Instance;
// Let base class update the collection
object ret = base.SetItems(editValue, value);return ret;
}
}I ha
-
Suppose I have the following class :
public class A
{
public bool Boolean {get; set;}public List<B> ListOfB {get; set;}
}public class B
{
public String StringValue {get; set;}public List<String> OneList {get; set;}
public List<String> AnotherList {get; set;}
}I want to expose the class A and under it the B class in a propertygrid. I have tried a lot of thing, but no help. May be I am missing something. What I did is as follows :
[DefaultProperty("ListOfB")]
public class A
{
[Browsable(false)]
public bool Boolean {get; set;}[Category("Visuals")]
[Description("YZYZYZ")]
[MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Localizable(true)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Editor(typeof(BListEditor), typeof(UITypeEditor))]
public List<B> ListOfB {get; set;}}
public class B
{
public String StringValue {get; set;}[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[Category("Visuals")]
[Description("XXYZ")]
[MergableProperty(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<String> OneList {get; set;}[Description("PPPWRT")]
[MergableProperty(true)]
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[Category("Visuals")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<String> AnotherList {get; set;}
}public class BListEditor : CollectionEditor
{
public BListEditor()
: base(typeof(List<B> ) )
{ }protected override Type[] CreateNewItemTypes()
{
return new Type[] {typeof(B)};
}protected override object SetItems(object editValue, object[] value)
{
// Cast the context into the expected control type
A settings = (A)Context.Instance;
// Let base class update the collection
object ret = base.SetItems(editValue, value);return ret;
}
}I ha
It sounds like the
ExpandableObjectConverter
might be what you need. You can look that up on MSDN, or Google for it (you'll get lots of hits). Take a look at Add Custom Properties to a PropertyGrid[^], it shows several methods to get what it sounds like you want to do.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
It sounds like the
ExpandableObjectConverter
might be what you need. You can look that up on MSDN, or Google for it (you'll get lots of hits). Take a look at Add Custom Properties to a PropertyGrid[^], it shows several methods to get what it sounds like you want to do.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Thanks I'll try
Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..