Properties with the same name throws an exception

3 posts, 0 answers
  1. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 11 Feb 2013 Link to this post

    var item1 = new PropertyStoreItem(typeof(String), "Name", "Value", "", "Category 1", false);
    var item2 = new PropertyStoreItem(typeof(String), "Name", "Value", "", "Category 2", false);
    store.Add(item1);
    store.Add(item2);

    System.ArgumentException
    Additional information: An item with the same name already exists in the collection. Item name: Name

    Q: How do I add two categories with properties with the same name?
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 14 Feb 2013 Link to this post

    Hi Kristoffer,

    Thank you for writing.

    The restriction on duplicate names when adding property store items is provoked by the fact that you cannot have an actual object with two properties with the same name. Such a class/struct would not even compile. 

    To get two properties to display the same name you can use the Label property of each property store item. The text set to the Label property is displayed in RadPropertyGrid. You still have to use unique names for the properties, though.

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

    Regards,
    Ivan Petrov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 14 Feb 2013 Link to this post

    Thanks for the clarification!

    Setting item.DisplayName (label?) solved the problem.
Back to Top