Using a Stuct as a PropertyStoreItem's Value

5 posts, 1 answers
  1. Paul
    Paul avatar
    23 posts
    Member since:
    Feb 2013

    Posted 25 Feb 2013 Link to this post

    I'm trying to display a struct in a RadPropertyGrid (similar to the "Padding" item in the "First Look" example), but for some reason items in the struct is not displayed as an expandable item like in the "First Look" example. Instead, the value of my PropertyStoreItem is just set to a string containing namespace of my struct (see the attached screenshot). Here is the struct I'm trying to use:

    namespace DSI.WorkFlow
    {
        struct SearchItem
        {
            string fromField;
            string toField;
     
            [Description("Search value.")]
            [Category("Search Fields")]
            [DefaultValue(null)]
            [Browsable(true)]
            public string FromField
            {
                get
                {
                    return this.fromField;
                }
                set
                {
                    this.fromField = value;
                }
            }
     
            [Description("Search value.")]
            [Category("Search Fields")]
            [DefaultValue(null)]
            [Browsable(true)]
            public string ToField
            {
                get
                {
                    return this.toField;
                }
                set
                {
                    this.toField = value;
                }
            }
        }
    }


    Do you have any idea what I'm missing?
  2. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 28 Feb 2013 Link to this post

    Hi Paul,

    Thank you for writing.

    To make an expandable property you will need to provide a TypeConverter for the type you want to be expandable. You can check out this article which explains how to get most out of your standard property grid. All of the things are applicable to RadPropertyGrid as well.

    I have also attached an example project where the struct from your post is displayed as an expandable property.

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Kind regards,
    Ivan Petrov
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Karan
    Karan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 23 May in reply to Ivan Petrov Link to this post

    Hi Ivan,

    Thank you very much for your example. I have a similar problem where I am trying to add a 'Position' item to my PropertyGrid (containing X, Y, Z values). Using your example, I manage to add a single row with a collapsible 'Position' with individual X,Y,Z which appear after I expand the the row.

    However, I wish to add multiple rows and the approach I am following is -

    1. Create multiple PropertyStoreItems
    2. Adding these to a RadPropertyStore
    3. RadPropertyGrid.SelectedObject = RadPropertyStore

    How can I achieve adding multiple Position rows which can be expanded to reveal X,Y,Z values using the above approach? Looking forward to your reply. Thanks.
  5. Karan
    Karan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 24 May Link to this post

    Does anyone have an idea how this can be achieved?
  6. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 25 May Link to this post

    Hello Karan,

    Thank you for writing. 
     
    When you populate the RadPropertyGrid with RadPropertyStore, note that you can specify the TypeConverterAttribute for each PropertyStoreItem by adding it to the PropertyStoreItem.Attributes collection. Thus, you can add as many PropertyStoreItems as you wish in order to specify the custom TypeConverter:
     
    PropertyStoreItem item1 = new PropertyStoreItem(typeof(Example), "Property1", new Example());
    item1.Attributes.Add(new TypeConverterAttribute(typeof(SearchItemConverter)));
    PropertyStoreItem item2 = new PropertyStoreItem(typeof(Example), "Property2", new Example());
    item2.Attributes.Add(new TypeConverterAttribute(typeof(SearchItemConverter)));
      
    RadPropertyStore store = new RadPropertyStore();
    store.Add(item1);
    store.Add(item2);
    this.radPropertyGrid1.SelectedObject = store;

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready