the 'add' and 'delete' button are grayed out.
I tried to change the property type to List<string> and 'delete' would be usable but 'add' still not.
Could you give me some example of how to enable the full functionality of collection editor?>
The property definition in the object bind to RadPropertyGrid:
string[] _mdAddresses;
public string[] MdAddresses
{
get { return _mdAddresses; }
set { _mdAddresses = value; }
}
11 Answers, 1 is accepted
The ability to insert and delete items depends entirely on your source collection (whether it supports such functionality) and your business object (whether it has a default constructor). Could you try doing the same with another control (DataGrid, RadGridView, ListBox) to verify if you can add new items ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Johnny's collection doesn't work because it uses a fixed size collection. I recomand using ObservableCollection<T>.
This works ok with all kinds of classes, except, as I noticed, with simple types, like string or int. Is this because it doesn't have a default constructor, or because some are value types?
What's the solution?
Thanks
Alex
My recommendation would be to create a business object with default constructor. This object could have a string property that you can use for setting the strings you want and displaying them in the grid.
Regards,
Maya
Telerik
Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).
Thanks for your prompt response.
However, I can't change the collection. It is part of an external dll I am trying to call, based on values set in the property grid (similar to the Telerik example of binding the property grid to a control on the UI, where you can't change the types of the properties of the objects you interact with)
Is there any other way to bypass the default constructor requirement?
Alex
I have just replied to your support ticket on the same topic.
Regards,
Yoan
Telerik
Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).
Thanks for your answer
Alex
Hi,
I'm also interested in an solution. Did you fix it?
I want to bind a list of strings to the CollectionEditor, but I cannot add elements.
For your convenience, I prepared an example to demonstrate how to add element in the CollectionEditor. Please take a look at the implementation and consider how this approach fits your scenario.
I hope that this helps.Regards,
Martin Vatev
Telerik
Hi Martin,
thanks for your reply and your sample. With custom classes I do not have any issues.
To clearify: I have an IList<string> and want to add new strings to the collection (delete does behave as expected). Can you tell me how to get it? I cannot change the type from string to whatever in the property.
A possible approach would be to define a custom data type acting as a string. Since System.String is a sealed class and cannot be inherited, I suggest you using an implicit operator.
A possible implementation of the aforementioned custom string would look as follows.
public
class
CustomString
{
string
_value;
public
CustomString()
{
}
public
CustomString(
string
value)
{
this
._value = value;
}
public
static
implicit
operator
string
(CustomString s)
{
return
s.ToString();
}
public
static
implicit
operator
CustomString(
string
s)
{
return
new
CustomString(s);
}
public
string
Value
{
get
{
return
this
._value; }
set
{
if
(
this
._value != value)
{
this
._value = value;
}
}
}
public
override
string
ToString()
{
return
_value.ToString();
}
}
Note, that you need bind the Text property of the TextBlock defined in the ItemTemplate to the Value property of the custom string.
I have also modified the sample project with the approach for your convenience.
Let me know how this works for you.
Best Regards,
Stefan
Telerik