How to handle a List<string> property in the PropertyGrid?

8 posts, 0 answers
  1. Laurent
    Laurent avatar
    15 posts
    Member since:
    Sep 2015

    Posted 05 Oct 2015 Link to this post

    I have a read-only List<string> property in my business object.

    How do I make it show up in the property grid. Do I need to create a custom editor?

    Thanks!
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Oct 2015 Link to this post

    Hello Laurent,

    Please check out the "CollectionEditors" article for a reference. 

    Regards,
    Maya
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Laurent
    Laurent avatar
    15 posts
    Member since:
    Sep 2015

    Posted 06 Oct 2015 Link to this post

    CollectionEditor works well for lists of objects with many properties, including one that can be used as a selector.

    For simple lists of values or strings, it seems like there is no good solution.

  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Oct 2015 Link to this post

    Hello Laurent,

    I attached a sample illustrating a case with RadPropertyGrid displaying an item with List<string> property. As you can see, CollectionEditor is its editor. Does this scenario correspond to yours or am I missing anything ? 


    Regards,
    Maya
    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
  6. Laurent
    Laurent avatar
    15 posts
    Member since:
    Sep 2015

    Posted 07 Oct 2015 Link to this post

    Hello Maya,

    Yes, your solution works. Please don't take it personally but this is a bad one.You have to click the drop-down button to see the strings, you get a giant panel, two non functional buttons (because readonly) and a right panel that's mostly useless... Here is below what I ended up with: Bind the read-only strings to a custom editor template with just a listbox.

     

    <telerik:PropertyDefinition.EditorTemplate
        <DataTemplate>                            
    <ListBox 
    ItemsSource="{Binding Path=Strings}" />
    </DataTemplate>
    </telerik:PropertyDefinition.EditorTemplate>​

  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 08 Oct 2015 Link to this post

    Hello Laurent,

    Displaying a CollectionEditor for collection properties is the default scenario and its functionality (displaying anything in the field/having enabled/disabled buttons) depends entirely on the type of the source collection.

    Still, it is great that found the most appropriate solution for your scenario. Let us know in case you need further assistance with Telerik controls. 


    Regards,
    Maya
    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
  8. Dharmavaram
    Dharmavaram avatar
    73 posts
    Member since:
    Jun 2013

    Posted 30 Sep in reply to Maya Link to this post

    Hi Maya,

    I too have similar requirement but I have to store this information back in my property how can I achieve it.how to get the selected item from ListBox and store it in property.

    Regards,

    Nagasree

  9. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 04 Oct Link to this post

    Hello Nagasree,

    If you are using the approach with the ListBox in the EditorTemplate, you can bind ListBox's SelectedItem to some your property.

    Regards,
    Yoan
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready