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

[Solved] Treeview subnode bind into a list of string

3 Answers 131 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
al
Top achievements
Rank 1
al asked on 14 Apr 2009, 08:06 AM

Hi! can anyone help me with this.
I am using a treeview for silverlight and i want to bind the subnode into a list of string List<String>.

<

 

UserControl.Resources>

 

 

 

<ds:RenderData x:Key="Data"/>

 

 

 

 

 

 

 

 

<telerik:HierarchicalDataTemplate x:Key="Node" ItemsSource="{Binding SubNode}">

 

 

 

        <TextBlock Text="{Binding Name}"/>

 

 

 

        </telerik:HierarchicalDataTemplate>

 

 

 

<telerik:HierarchicalDataTemplate x:Key="Node" ItemsSource="{Binding SubNode}">

 

 

 

 

 

</UserControl.Resources>

 

 

 

 


<
Grid x:Name="LayoutRoot" Background="White">

 

 

 

        <telerikNavigation:RadTreeView ItemsSource="{Binding Source={StaticResource Data}}"

 

 

                                    ItemTemplate="{StaticResource Node}">

 

 

 

                    <TextBlock Text="{Binding SubNode}"/>

 

 

 

        </telerikNavigation:RadTreeView>

 

 

 

</Grid>

 

 

 


public

 

class Node

 

{

 

public Node(String NodeName)

 

{

        Name = NodeName;

        SubNode =

new List<String>();

 

}

 

public string Name

 

{

 

        get;  

 

 

        set;

 

}

 

public List<String> SubNode

 

{

 

        get;

 

 

        set;

 

}

}

 

public class RenderData : List<Node>

 

{

 

    public RenderData()

 

        {

 

            Node tmpChild;

 

            Add(tmpChild =

new Node("A"));

 

            tmpChild.SubNode.Add(

"A.1");

 

            tmpChild.SubNode.Add(

"A.2");

 

            Add(tmpChild =

new Node("B"));

 

            tmpChild.SubNode.Add(

"B.1");

 

            tmpChild.SubNode.Add(

"B.2");

 

 

            Add(tmpChild =

new Node("C"));

 

            tmpChild.SubNode.Add(

"C.1");

 

            tmpChild.SubNode.Add(

"C.2");

 

 

            Add(tmpChild =

new Node("D"));

 

            tmpChild.SubNode.Add(

"D.1");

 

            tmpChild.SubNode.Add(

"D.2");

 

 

            Add(tmpChild =

new Node("E"));

 

            tmpChild.SubNode.Add(

"E.1");

 

            tmpChild.SubNode.Add(

"E.2");

 

 

            Add(tmpChild =

new Node("F"));

 

            tmpChild.SubNode.Add(

"F.1");

 

            tmpChild.SubNode.Add(

"F.2");

 

 

            Add(tmpChild =

new Node("G"));

 

            tmpChild.SubNode.Add(

"G.1");

 

            tmpChild.SubNode.Add(

"G.2");

 

 

            Add(tmpChild =

new Node("H"));

 

            tmpChild.SubNode.Add(

"H.1");

 

            tmpChild.SubNode.Add(

"H.2");

 

 

    }

}

base on the samples that i have seen, they are all bind in a list of objects List<well> or List<Person>.
HOw do you bind a List<String>?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 15 Apr 2009, 04:05 PM
Hello al,

You can preview the attached example where such approach is demonstrated.

Kind regards,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
al
Top achievements
Rank 1
answered on 16 Apr 2009, 01:53 AM
Can you show me how to do it with a sub item? its like this.

public class A
{
    public A()
    {
    }

    public string Name
    {
        get;set;
    }

    public List<String> Ancestor
    {
        get;set;
    }
}

0
Ivan
Telerik team
answered on 16 Apr 2009, 11:07 AM
Hi al,

Could you please give us some more details on what your goals are? Also, what you did you mean by "with a sub item" phrase - did you intend to bind each treeview item to a different object.

Greetings,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
al
Top achievements
Rank 1
Answers by
Ivan
Telerik team
al
Top achievements
Rank 1
Share this question
or