This is a migrated thread and some comments may be shown as answers.

Using a Stuct as a PropertyStoreItem's Value

4 Answers 189 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 25 Feb 2013, 09:25 PM
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?

4 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 28 Feb 2013, 03:06 PM
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.
0
Karan
Top achievements
Rank 1
answered on 23 May 2016, 08:38 AM
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.
0
Karan
Top achievements
Rank 1
answered on 24 May 2016, 05:56 AM
Does anyone have an idea how this can be achieved?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 May 2016, 12:17 PM
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.
Tags
PropertyGrid
Asked by
Paul
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Karan
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or