Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can edit field of an Expandable Property in the property grid?
    text
    copied!<p>I created a custom control with several properties. I add some expandable property to my custom control. Now, I want that user can edit expandable property field in the property grid and new entered values set for their related properties. My expandable property in the property grid is "Required Sign" and has two sub properties as follows:</p> <ol> <li><p>ForeColor</p></li> <li><p>Visible</p></li> </ol> <p>I set two sub properties' values of the "Required Sign" expandable property to the field of the "Required Sign" property as you can see in the following figure:</p> <p><img src="https://i.stack.imgur.com/p09zy.jpg" alt="&quot;Required Sign&quot; expandable property"></p> <ol> <li><p>Green Box: "Required Sign" Expandable Property</p></li> <li><p>Blue Box: Two sub properties of the "Required Sign" Expandable Property</p></li> <li><p>Red Box: Field of the "Required Sign" Expandable Property</p></li> </ol> <p>However, I can't change or edit field values of the "Required Sign" expandable property directly. How can I change or edit field values of expandable property (Red Box in the figure)?</p> <p>My codes as follows:</p> <pre><code>[DisplayName("Label Information")] [Description("Label Informationnnnnnnnnnnnnnnn")] [DefaultProperty("Text")] [DesignerCategory("Component")] [TypeConverter(typeof(AllFloorsContentsLabelInformationTypeConverter))] public class AllFloorsContentsLabelInformation : LabelX { private AllFloorsContentsLabelRequiredSignInformation allFloorsContentsLabelRequiredSignInformation = new AllFloorsContentsLabelRequiredSignInformation(); public AllFloorsContentsLabelInformation() { } [Category("Data")] [DisplayName("Required Sign")] [Description("Required Signnnnnnnnnnnnnnn")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public AllFloorsContentsLabelRequiredSignInformation AllFloorsContentsLabelRequiredSignInfo { get { return allFloorsContentsLabelRequiredSignInformation; } } } [DisplayName("Required Sign Information")] [Description("Required Sign Informationnnnnnnnnnnnnnnn")] [DefaultProperty("Text")] [DesignerCategory("Component")] [TypeConverter(typeof(AllFloorsContentsLabelRequiredSignInformationTypeConverter))] public class AllFloorsContentsLabelRequiredSignInformation { private Color foreColor = Color.Red; private ConfirmationAnswers visible = ConfirmationAnswers.Yes; public AllFloorsContentsLabelRequiredSignInformation() { } [Category("Appearance")] [DisplayName("ForeColor")] [Description("ForeColor")] [DefaultValue(typeof(Color), "Red")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public new Color ForeColor { get { return foreColor; } set { foreColor = value; } } [Category("Behavior")] [DisplayName("Visible")] [Description("Visibleeeeeeeeeeeeeeeeee")] [DefaultValue(ConfirmationAnswers.Yes)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ConfirmationAnswers Visible { get { return visible; } set { visible = value; } } } public class AllFloorsContentsLabelRequiredSignInformationTypeConverter : ExpandableObjectConverter//TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(AllFloorsContentsLabelRequiredSignInformation)) { return true; } return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(String) &amp;&amp; value is AllFloorsContentsLabelRequiredSignInformation) { AllFloorsContentsLabelRequiredSignInformation allFloorsContentsLabelRequiredSignInformation = (AllFloorsContentsLabelRequiredSignInformation)value; return allFloorsContentsLabelRequiredSignInformation.ForeColor.ToString() + "; " + allFloorsContentsLabelRequiredSignInformation.Visible.ToString(); } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { AllFloorsContentsLabelRequiredSignInformation allFloorsContentsLabelRequiredSignInformation = new AllFloorsContentsLabelRequiredSignInformation(); string strExtractData = (string)value; Color clrForeColor = Color.FromName(strExtractData.Substring(0, strExtractData.IndexOf(";") - 1).Trim()); string strVisible = strExtractData.Substring(strExtractData.IndexOf(";") + 1, strExtractData.Length).Trim(); allFloorsContentsLabelRequiredSignInformation.ForeColor = clrForeColor; if (strVisible == "Yes") { allFloorsContentsLabelRequiredSignInformation.Visible = ConfirmationAnswers.Yes; } else { allFloorsContentsLabelRequiredSignInformation.Visible = ConfirmationAnswers.No; } return allFloorsContentsLabelRequiredSignInformation; } return base.ConvertFrom(context, culture, value); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload