Update SelectedNode.DataBoundItem

3 posts, 1 answers
  1. jed
    jed avatar
    9 posts
    Member since:
    Feb 2012

    Posted 17 Oct 2013 Link to this post

    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. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 18 Oct 2013 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. jed
    jed avatar
    9 posts
    Member since:
    Feb 2012

    Posted 19 Oct 2013 Link to this post

    thanks a lot

    INotifyPropertyChanged i tried but without BindingList

    now it works as expected
Back to Top