Node not being removed from DataSource

4 posts, 1 answers
  1. Thomas
    Thomas avatar
    19 posts
    Member since:
    Oct 2012

    Posted 03 Nov 2017 Link to this post

    Hi,

    Spent some time today with the RadTreeView and can't figure out why a node is removed fine from the DS when using 

                radTreeView1.DisplayMember = "Name";
                radTreeView1.ValueMember = "Id";

    But not when using:

                radTreeView1.DisplayMember = "Name\\ChildName";
                radTreeView1.ChildMember = "list\\ChildObjects";

    Regards,

    Thomas

    See code below:

    namespace RadTreeViewTest
    {
        public partial class RadForm1 : Telerik.WinControls.UI.RadForm
        {
            BindingList<MyObject> list = new BindingList<MyObject>();
            int counter = 0;
            public RadForm1()
            {
                InitializeComponent();
                list.ListChanged += List_ListChanged;
                radTreeView1.DataSource = list;
                radTreeView1.DisplayMember = "Name\\ChildName";
                radTreeView1.ChildMember = "list\\ChildObjects";
                //radTreeView1.DisplayMember = "Name";
                //radTreeView1.ValueMember = "Id";
            }
     
            private void List_ListChanged(object sender, ListChangedEventArgs e)
            {
                radLabel1.Text = ""+list.Count;
            }
     
            private void radButton1_Click(object sender, EventArgs e)
            {
                list.Add(new MyObject(counter++, "Test " + counter, 5));
            }
        }
     
        public class MyObject : INotifyPropertyChanged
        {
            private int id;
            public int Id
            {
                get { return id; }
                set { SetField(ref id, value, "Id"); }
            }
            private string name;
            public string Name
            {
                get { return name; }
                set { SetField(ref name, value, "Name"); }
            }
     
            private int counter;
            public int Counter
            {
                get { return counter; }
                set { SetField(ref counter, value, "Counter"); }
            }
            public BindingList<ChildObject> ChildObjects { get; set; }
            public MyObject()
            {
     
            }
            public MyObject(int i, string n, int c)
            {
                ChildObjects = new BindingList<ChildObject>();
                this.Id = i; this.Name = n;this.Counter = c;
                ChildObjects.Add(new ChildObject(i, "ghejwgk 1"));
                ChildObjects.Add(new ChildObject(i, "ghejwgk 2"));
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            protected virtual void OnPropertyChanged(string propertyName)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
            protected bool SetField<T>(ref T field, T value, string propertyName)
            {
                if (EqualityComparer<T>.Default.Equals(field, value)) return false;
                field = value;
                OnPropertyChanged(propertyName);
                return true;
            }
        }
        public class ChildObject
        {
            public int ParentId { get; set; }
            public string ChildName { get; set; }
     
            public ChildObject(int i, string n)
            {
                this.ParentId = i; this.ChildName = n;
            }
        }
    }
  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3224 posts

    Posted 07 Nov 2017 Link to this post

    Hello, Thomas,

    Thank you for writing.  

    This a known issue when deleting a node via the context menu. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

    Currently, feel free to use the suggested solution in the item.

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Thomas
    Thomas avatar
    19 posts
    Member since:
    Oct 2012

    Posted 07 Nov 2017 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess,

    Thank you for the answer.

    By the way, as far as I can see this behavior also occur when deleting by the 'Del' btn.

     

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3224 posts

    Posted 07 Nov 2017 Link to this post

    Hello, Thomas,    

    Thank you for writing back. 

    Actually, the same logic is performed when removing a node with pressing the Del key. In order to cover this case, you can handle the RadTreeView.NodeRemoved event and delete the associated record from the DataSource collection. 

    I hope this information helps. If you have any additional questions, please let me know. 

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top