Unable to create complex property of custom control

I am trying to create a multi-component complex construction of a user control, but the written code for it does not work, only the property value only only, available only in the Property Explorer. Here is the code for it

private MyComboProperties _MyComboProperties; public MyComboProperties MyComboPropertiesValues { get { return _MyComboProperties; } set { _MyComboProperties = value; } } //MyComboProperties struct is like this [System.Runtime.InteropServices.ComVisible(true)] public struct MyComboProperties { private string _MySourceQuery; private string _MyDisplayMember; private string _MyValueMember; public MyComboProperties(string mySourceQuery, string myDisplayMember, string myValueMember) { _MySourceQuery = mySourceQuery; _MyDisplayMember = myDisplayMember; _MyValueMember = myValueMember; } public string MySourceQuery { get { return _MySourceQuery; } set { _MySourceQuery = value; } } public string MyDisplayMember { get { return _MyDisplayMember; } set { _MyDisplayMember = value; } } public string MyValueMember { get { return _MyValueMember; } set { _MyValueMember = value; } } } 

Or someone will provide me sample code for Multi Value Custom Control with 3 input string values.

+4
source share
1 answer

Use the code below to achieve your goal.

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Drawing; using System.Globalization; namespace ExpandableMultiValuedCustomControl { public partial class MyComboBox : System.Windows.Forms.ComboBox { private MyComboProperties _comboProperties = new MyComboProperties(); public MyComboBox() { InitializeComponent(); } public MyComboBox(IContainer container) { container.Add(this); InitializeComponent(); } [Category("My Combo Properties")] [DisplayName("My Combo Properties")] [Description("My Combo Properties")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public MyComboProperties MyComboProperties { get { return _comboProperties; } set { _comboProperties = value; } } } [DisplayName("My Combo Properties")] [Description("CMy Combo Properties")] [DefaultProperty("Text")] [DesignerCategory("Component")] [TypeConverter(typeof(ExpandableObjectConverter))] public class MyComboProperties { private string _MySourceQuery; private string _MyDisplayMember; private string _MyValueMember; public MyComboProperties() { } [Category("MyComboBoxProperties")] [DisplayName("MySourceQuery")] [Description("MySourceQuery")] public string MySourceQuery { get { return _MySourceQuery; } set { _MySourceQuery = value; } } [Category("MyComboBoxProperties")] [DisplayName("MyDisplayMember")] [Description("MyDisplayMember")] public string MyDisplayMember { get { return _MyDisplayMember; } set { _MyDisplayMember = value; } } [Category("MyComboBoxProperties")] [DisplayName("MyValueMember")] [Description("MyValueMember")] public string MyValueMember { get { return _MyValueMember; } set { _MyValueMember = value; } } } } 

And to access these properties you must access as follows:

 myComboBox1.MyComboProperties.MyDisplayMember myComboBox1.MyComboProperties.MyValueMember myComboBox1.MyComboProperties.MySourceQuery 
+2
source

Source: https://habr.com/ru/post/1499332/


All Articles