Collection editor cannot 'add' or 'delete'

12 posts, 0 answers
  1. johnny
    johnny avatar
    1 posts
    Member since:
    Dec 2010

    Posted 26 Jan 2013 Link to this post

    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; }
            }

  2. Jerome
    Jerome avatar
    87 posts
    Member since:
    Aug 2010

    Posted 08 Feb 2013 Link to this post

    I am having this same issue. Looking around for a read-only property or something, but cannot find anything.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Feb 2013 Link to this post

    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.

  5. Alexandru
    Alexandru avatar
    16 posts
    Member since:
    Nov 2012

    Posted 13 Feb 2014 Link to this post

    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


  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 13 Feb 2014 Link to this post

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

  7. Alexandru
    Alexandru avatar
    16 posts
    Member since:
    Nov 2012

    Posted 13 Feb 2014 in reply to Maya Link to this post

    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
  8. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 17 Feb 2014 Link to this post

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

  9. Alexandru
    Alexandru avatar
    16 posts
    Member since:
    Nov 2012

    Posted 18 Feb 2014 in reply to Yoan Link to this post

    Hello Yoan!

    Thanks for your answer

    Alex
  10. Richard
    Richard avatar
    9 posts
    Member since:
    Aug 2012

    Posted 15 Sep 2015 Link to this post

    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.

  11. Martin Vatev
    Admin
    Martin Vatev avatar
    90 posts

    Posted 16 Sep 2015 Link to this post

    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
  12. Richard
    Richard avatar
    9 posts
    Member since:
    Aug 2012

    Posted 17 Sep 2015 Link to this post

    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.

  13. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 21 Sep 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready