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

Collection editor cannot 'add' or 'delete'

11 Answers 479 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
johnny
Top achievements
Rank 1
johnny asked on 26 Jan 2013, 11:43 AM
I'm using auto generating for a object which has a property of type string[].
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

Sort by
0
Jerome
Top achievements
Rank 1
answered on 09 Feb 2013, 12:21 AM
I am having this same issue. Looking around for a read-only property or something, but cannot find anything.
0
Maya
Telerik team
answered on 11 Feb 2013, 07:27 AM
Hello Jerome,

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 ?  

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Alexandru
Top achievements
Rank 1
answered on 13 Feb 2014, 07:05 AM
Hi!

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


0
Maya
Telerik team
answered on 13 Feb 2014, 08:00 AM
Hello Alexandru,

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).

0
Alexandru
Top achievements
Rank 1
answered on 13 Feb 2014, 08:15 AM
Hi Maya!

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
0
Yoan
Telerik team
answered on 17 Feb 2014, 01:39 PM
Hello 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).

0
Alexandru
Top achievements
Rank 1
answered on 18 Feb 2014, 06:27 AM
Hello Yoan!

Thanks for your answer

Alex
0
Richard
Top achievements
Rank 1
answered on 15 Sep 2015, 01:23 PM

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.

0
Martin
Telerik team
answered on 16 Sep 2015, 01:53 PM
Hello Richard,

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
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
0
Richard
Top achievements
Rank 1
answered on 17 Sep 2015, 07:17 AM

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.

0
Stefan
Telerik team
answered on 21 Sep 2015, 02:35 PM
Hi Richard,

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
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
Tags
PropertyGrid
Asked by
johnny
Top achievements
Rank 1
Answers by
Jerome
Top achievements
Rank 1
Maya
Telerik team
Alexandru
Top achievements
Rank 1
Yoan
Telerik team
Richard
Top achievements
Rank 1
Martin
Telerik team
Stefan
Telerik team
Share this question
or