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

Update SelectedNode.DataBoundItem

2 Answers 93 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
jed
Top achievements
Rank 1
jed asked on 17 Oct 2013, 06:38 PM
Hi,

i am trying to build an editable TreeView:

if selectedNade change the current selected value goes to a radtextbox:

private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
        {
                TestItem item = radTreeView1.SelectedNode.DataBoundItem as TestItem;
                if (item != null)
                {
                    radTextBox1.Text = item.Name;
                    radTextBox1.Enabled = true;
                }
        }

on KeyUp Event i store the value back:

private void radTextBox1_KeyUp(object sender, KeyEventArgs e)
{
    if (radTreeView1.SelectedNode != null)
    {
        TestItem item = radTreeView1.SelectedNode.DataBoundItem as TestItem;
        if (item != null)
        {
            item.Name = radTextBox1.Text;
        }
    }
}

this doesn't work immediately, but if i click on another node then the last node updates correctly. i tried refresh(), update() and implementing INotifyPropertyChanged, but nothing worked

is live updateing possible?

greetings

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Oct 2013, 03:34 PM
Hello Jed,

Thank you for contacting Telerik Support.

Please find attached a sample project where changing the text in the RadTextBox immediately affects the corresponding RadTreeNode. For this purpose it is necessary to use BindingList instead of List and TestItem class should implement INotifyPropertyChanged as it is described in the following help article.
public class TestItem : System.ComponentModel.INotifyPropertyChanged
 
{
 
    public event PropertyChangedEventHandler PropertyChanged;
 
   
 
    protected virtual void OnPropertyChanged(string propertyName)
 
    {
 
        if (PropertyChanged != null)
 
        {
 
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
 
        }
 
    }
 
   
 
//some other properties and fields 
 
   
 
   public string Name
 
   {
 
       get
 
       {
 
           return _name;
 
       }
 
       set
 
       {
 
           _name = value;
 
           OnPropertyChanged("Name");
 
       }
 
   }
 
   
 
}

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

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
jed
Top achievements
Rank 1
answered on 19 Oct 2013, 09:11 AM
thanks a lot

INotifyPropertyChanged i tried but without BindingList

now it works as expected
Tags
Treeview
Asked by
jed
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
jed
Top achievements
Rank 1
Share this question
or