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

Q1 - 2011

3 Answers 46 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 06 Apr 2011, 11:29 PM
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?



3 Answers, 1 is accepted

Sort by
0
Troy
Top achievements
Rank 1
answered on 06 Apr 2011, 11:46 PM
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
0
Svett
Telerik team
answered on 12 Apr 2011, 02:23 PM
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
0
Troy
Top achievements
Rank 1
answered on 12 Apr 2011, 05:33 PM
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.
Tags
Treeview
Asked by
Troy
Top achievements
Rank 1
Answers by
Troy
Top achievements
Rank 1
Svett
Telerik team
Share this question
or