How to add sub class to property grid

3 posts, 0 answers
  1. Myoungsu
    Myoungsu avatar
    7 posts
    Member since:
    Jul 2015

    Posted 03 Nov 2015 Link to this post

    I have two classes

    One is EQConfig, the other is HSMSConfig (I attached) and EQConfig has a property which name is hsmsConfig and HSMSConfig type.

    Then, I set below

    this.radPropertyGrid1.SelectedObject = EQConfig;

    Then I expected I can expand hsmsConfig property like

  2. Myoungsu
    Myoungsu avatar
    7 posts
    Member since:
    Jul 2015

    Posted 03 Nov 2015 Link to this post

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.IO;
    using System.Xml.Serialization;
     
    namespace SCKIT.EQConfiguration
    {
        [Serializable, DefaultPropertyAttribute("DeviceID")]
        public class HSMSConfig
        {
            [Category("Default Setting"), Description("Equipment ID")]
            public string ID { get; set; }
     
            [Category("Default Setting"), Description("Active or Passive")]
            public ENUM_CONNECTION_MODE MODE { get; set; }
     
            [Category("Default Setting")]
            public string IP { get; set; }
     
            [Category("Default Setting"), Description("Please enter an integer between 0 and 65535.")]
            public int PORT { get; set; }
     
            [Category("Default Setting"), Description("Device ID")]
            public int DeviceID { get; set; }
     
            [Category("Timeout"), Description("Represents the time3(1~120) of hsms.")]
            public int T3 { get; set; }
     
            [Category("Timeout"), Description("Represents the time5(1~240) of hsms.")]
            public int T5 { get; set; }
     
            [Category("Timeout"), Description("Represents the time6(1~240) of hsms.")]
            public int T6 { get; set; }
     
            [Category("Timeout"), Description("Represents the time7(1~240) of hsms.")]
            public int T7 { get; set; }
     
            [Category("Timeout"), Description("Represents the time8(1~120) of hsms.")]
            public int T8 { get; set; }
     
            [Category("Timeout"), Description("Represents the LinkTestTime(1~120) of hsms.")]
            public int LinkTestTimeout { get; set; }
     
            [BrowsableAttribute(false)]
            public string LogFolderPath { get; set; }
     
     
            [Category("Log"), Description("SystemLog Enable/Disable")]
            public bool SystemLogWrite { get; set; }
     
            [Category("Log"), Description("SystemLog Maximum Count")]
            public int SystemLogCount { get; set; }
     
            [Category("Log"), Description("SystemLog Maximum Capacity")]
            public int SystemLogMaxCapacity { get; set; }
     
     
            [Category("Log"), Description("SMLLog Enable/Disable")]
            public bool SMLLogWrite { get; set; }
     
            [Category("Log"), Description("SMLLog Maximum Count")]
            public int SMLLogCount { get; set; }
     
            [Category("Log"), Description("SMLLog Maximum Capacity")]
            public int SMLMaxCapacity { get; set; }
     
     
            [Category("Log"), Description("HexaLog Enable/Disable")]
            public bool HEXLogWrite { get; set; }
     
            [Category("Log"), Description("HexaLog Maximum Count")]
            public int HEXLogCount { get; set; }
     
            [Category("Log"), Description("HexaLog Maximum Capacity")]
            public int HEXLogMaxCapacity { get; set; }
     
     
            public HSMSConfig()
            {
                initialize();
            }
            public HSMSConfig(string id)
            {
                initialize();
            }
     
            private void initialize()
            {
                MODE = ENUM_CONNECTION_MODE.ACTIVE;
                IP = string.Empty;
                PORT = 5000;
                DeviceID = 0;
                T3 = 45;
                T5 = 10;
                T6 = 5;
                T7 = 10;
                T8 = 5;
                LinkTestTimeout = 10;
                LogFolderPath = string.Empty;
     
                SystemLogWrite = false;
                SystemLogCount = 10;
                SystemLogMaxCapacity = 10;
     
                SMLLogWrite = false;
                SMLLogCount = 10;
                SMLMaxCapacity = 10;
     
                HEXLogWrite = false;
                HEXLogCount = 10;
                HEXLogMaxCapacity = 10;
            }
     
            public string GetXmlString()
            {
                try
                {
                    // Create a new XmlSerializer instance with the type of the test class
                    XmlSerializer SerializerObj = new XmlSerializer(typeof(HSMSConfig));
     
                    // Create a new file stream to write the serialized object to a file
                    StringWriter sw = new StringWriter();
                    SerializerObj.Serialize(sw, this);
     
                    return sw.ToString();
                }
                catch (Exception ex)
                {
                    return null;
                }
                finally
                {
                }
            }
        }
    }
    using
    System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.IO;
    using System.Xml.Serialization;
     
    namespace SCKIT.EQConfiguration
    {
        [Serializable, DefaultPropertyAttribute("DeviceID")]
        public class HSMSConfig
        {
            [Category("Default Setting"), Description("Equipment ID")]
            public string ID { get; set; }
     
            [Category("Default Setting"), Description("Active or Passive")]
            public ENUM_CONNECTION_MODE MODE { get; set; }
     
            [Category("Default Setting")]
            public string IP { get; set; }
     
            [Category("Default Setting"), Description("Please enter an integer between 0 and 65535.")]
            public int PORT { get; set; }
     
            [Category("Default Setting"), Description("Device ID")]
            public int DeviceID { get; set; }
     
            [Category("Timeout"), Description("Represents the time3(1~120) of hsms.")]
            public int T3 { get; set; }
     
            [Category("Timeout"), Description("Represents the time5(1~240) of hsms.")]
            public int T5 { get; set; }
     
            [Category("Timeout"), Description("Represents the time6(1~240) of hsms.")]
            public int T6 { get; set; }
     
            [Category("Timeout"), Description("Represents the time7(1~240) of hsms.")]
            public int T7 { get; set; }
     
            [Category("Timeout"), Description("Represents the time8(1~120) of hsms.")]
            public int T8 { get; set; }
     
            [Category("Timeout"), Description("Represents the LinkTestTime(1~120) of hsms.")]
            public int LinkTestTimeout { get; set; }
     
            [BrowsableAttribute(false)]
            public string LogFolderPath { get; set; }
     
     
            [Category("Log"), Description("SystemLog Enable/Disable")]
            public bool SystemLogWrite { get; set; }
     
            [Category("Log"), Description("SystemLog Maximum Count")]
            public int SystemLogCount { get; set; }
     
            [Category("Log"), Description("SystemLog Maximum Capacity")]
            public int SystemLogMaxCapacity { get; set; }
     
     
            [Category("Log"), Description("SMLLog Enable/Disable")]
            public bool SMLLogWrite { get; set; }
     
            [Category("Log"), Description("SMLLog Maximum Count")]
            public int SMLLogCount { get; set; }
     
            [Category("Log"), Description("SMLLog Maximum Capacity")]
            public int SMLMaxCapacity { get; set; }
     
     
            [Category("Log"), Description("HexaLog Enable/Disable")]
            public bool HEXLogWrite { get; set; }
     
            [Category("Log"), Description("HexaLog Maximum Count")]
            public int HEXLogCount { get; set; }
     
            [Category("Log"), Description("HexaLog Maximum Capacity")]
            public int HEXLogMaxCapacity { get; set; }
     
     
            public HSMSConfig()
            {
                initialize();
            }
            public HSMSConfig(string id)
            {
                initialize();
            }
     
            private void initialize()
            {
                MODE = ENUM_CONNECTION_MODE.ACTIVE;
                IP = string.Empty;
                PORT = 5000;
                DeviceID = 0;
                T3 = 45;
                T5 = 10;
                T6 = 5;
                T7 = 10;
                T8 = 5;
                LinkTestTimeout = 10;
                LogFolderPath = string.Empty;
     
                SystemLogWrite = false;
                SystemLogCount = 10;
                SystemLogMaxCapacity = 10;
     
                SMLLogWrite = false;
                SMLLogCount = 10;
                SMLMaxCapacity = 10;
     
                HEXLogWrite = false;
                HEXLogCount = 10;
                HEXLogMaxCapacity = 10;
            }
     
            public string GetXmlString()
            {
                try
                {
                    // Create a new XmlSerializer instance with the type of the test class
                    XmlSerializer SerializerObj = new XmlSerializer(typeof(HSMSConfig));
     
                    // Create a new file stream to write the serialized object to a file
                    StringWriter sw = new StringWriter();
                    SerializerObj.Serialize(sw, this);
     
                    return sw.ToString();
                }
                catch (Exception ex)
                {
                    return null;
                }
                finally
                {
                }
            }
        }
    }
    Sorry I didn't attached files
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 03 Nov 2015 Link to this post

    Hello Myoungsu,

    Thank you for writing.

    In order to achieve your goal, it is suitable to use an ExpandableObjectConverter. Additional information is available in PropertyGrid >> Type Converters help article.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top