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

Properties with the same name throws an exception

2 Answers 120 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Kristoffer
Top achievements
Rank 1
Kristoffer asked on 11 Feb 2013, 01:48 PM
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 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 14 Feb 2013, 01:28 PM
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.
0
Kristoffer
Top achievements
Rank 1
answered on 14 Feb 2013, 01:31 PM
Thanks for the clarification!

Setting item.DisplayName (label?) solved the problem.
Tags
PropertyGrid
Asked by
Kristoffer
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Kristoffer
Top achievements
Rank 1
Share this question
or