Edit dictionary property in RadPropertyGrid

5 posts, 0 answers
  1. Yaniv
    Yaniv avatar
    3 posts
    Member since:
    Jan 2012

    Posted 26 Oct 2014 Link to this post

    Hi,
    I'm using this really great control of RadPropertyGrid to generate grids dynamically for several types of objects.
    Lately, I tried to add object with property of dictionary (i.e. Dictionary<int, string> and no success on this try...

    What should I do?

    See my example at property called ItemsData (which is Dictionary<long, string>)
  2. Yaniv
    Yaniv avatar
    3 posts
    Member since:
    Jan 2012

    Posted 26 Oct 2014 Link to this post

    Ok, it seems to be working... 
    I just needed to initialize the Dictionary.
    But now, I see that I can't add new pair to the dictionary (the add button is disabled) and on pressing remove I get an exception.
    Also, I tried to use dictionary with custom type (i.e. Dictionary<int, Customer> and I couldn't edit the custom type.

    So my questions are:
    1 - How can I make the "add" and "Remove" buttons work safely?
    2 - Can I just write a custom control for those kind of complicated properties within the RadPropertyGrid?


  3. UI for WPF is Visual Studio 2017 Ready
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Oct 2014 Link to this post

    Hi Yaniv,

    Generally, add and remove buttons will be enabled if: 
    1. There is a default (parameterless) constructor of your business object.
    2. The source collection should support add/remove methods.

    My recommendation is to try working with another collection and ensure that there is a default constructor. 



    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Yaniv
    Yaniv avatar
    3 posts
    Member since:
    Jan 2012

    Posted 29 Oct 2014 in reply to Maya Link to this post

    Thanks, I understood that.
    But generally, It looks like this control doesnt support properties of type Dictionay.
    I managed to write a List class that implements the IDictionary to make it work and it works good only if the Dictionary has primitive types only. Doesn't work for Dictionary that holds custom class. While collection with custom class works good :-\

    Any suggestion?
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Nov 2014 Link to this post

    Hello Yaniv,

    I attach a sample project with a simple property grid holding object with a property of collection type. Could you update it so that it corresponds to your exact scenario and I can debug it on my side ? 
    You can either paste the code I need to add here (if it is not too much) or update directly the project and send it to me via support ticket. 


    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready