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

Node not being removed from DataSource

3 Answers 68 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 03 Nov 2017, 06:56 PM

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

3 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Nov 2017, 10:32 AM
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.
0
Thomas
Top achievements
Rank 1
answered on 07 Nov 2017, 10:42 AM

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.

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Nov 2017, 11:03 AM
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.
Tags
Treeview
Asked by
Thomas
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or