Q1 - 2011

4 posts, 0 answers
  1. Troy
    Troy avatar
    11 posts
    Member since:
    Apr 2009

    Posted 06 Apr 2011 Link to this post

    The Text and Value properties of the RadTreeNode are accessing the same thing. 

    For example: 

    RadTreeNode node = new RadTreeNode();
    node.Value = new RadTextBox();  // Text is changed to "Telerik.WinControls.UI.RadTextBox"
    node.Text = "Open TextBox"// Value is changed to  "Open TextBox"


    Is this how it is meant to work?



  2. Troy
    Troy avatar
    11 posts
    Member since:
    Apr 2009

    Posted 06 Apr 2011 Link to this post

    Okay I think I answered my own question.

     I need to override the ToString for my "Value"
    Or I suppose I could set the text and use Tag.

    Do you have a preferred method for setting / accessing data associated with a node?

    Thanks
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Svett
    Admin
    Svett avatar
    728 posts

    Posted 12 Apr 2011 Link to this post

    Hello Troy,

    Could you give us more information about your requirements? What do you want to achieve by setting the node's value property to the RadTextBox instance? If you want to place a text box control inside each node in RadTreeView, you should create a custom tree node by extending the RadTreeNodeElement and replacing the default one in the CreateNodeElement event:

    private void radTreeView1_CreateNodeElement(object sender, CreateTreeNodeElementEventArgs e)
    {
        e.NodeElement = new MyTreeNodeElement();
    }

    public class MyTreeNodeElement : TreeNodeElement
    {
        protected override TreeNodeContentElement CreateContentElement()
        {
            return new MyTreeNodeContentElement();
        }
     
        protected override System.Type ThemeEffectiveType
        {
            get
            {
                return typeof(TreeNodeElement);
            }
        }
    }

    public class MyTreeNodeContentElement : TreeNodeContentElement
    {
        private RadTextBoxElement textBoxElement;
     
        protected override System.Type ThemeEffectiveType
        {
            get
            {
                return typeof(TreeNodeContentElement);
            }
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
     
            this.textBoxElement = new RadTextBoxElement();
            this.textBoxElement.TextChanged += new System.EventHandler(textBoxElement_TextChanged);
            this.Children.Add(textBoxElement);
        }
     
        private void textBoxElement_TextChanged(object sender, System.EventArgs e)
        {
            this.NodeElement.Data.Text = textBoxElement.Text;
        }
     
        public override void Synchronize()
        {
            base.Synchronize();
            textBoxElement.Text = this.NodeElement.Data.Text;
        }
    }

    Regards,
    Svett
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  5. Troy
    Troy avatar
    11 posts
    Member since:
    Apr 2009

    Posted 12 Apr 2011 Link to this post

    Svett,

    Thanks for the reply.  This was just a poor made up example.  I was just trying to associate an object with the node.  So when the node was selected I could interact with the object.

    I think the right answer is to just use the tag field. 

    But thanks for the code anyway I think something like this will be useful in other places.
Back to Top