ComponentOne TreeView for ASP.NET WebForms
Task-Based Help / Adding a Child Node
In This Topic
    Adding a Child Node
    In This Topic

    This topic illustrates how to add a child node to a C1TreeViewNode control in Design view, in Source view, and in code. This topic assumes that you have completed Adding a Top-Level Node to a TreeView.

    In Design View

    Complete the following steps:

    1. Click the smart tag to open the C1TreeView Tasks menu. Select Edit TreeView.

      The C1TreeView Designer Form dialog box opens.

    2. Select the node you wish to add the child node to.
    3. Click the Add Child Item button to add the child node to the node you select. The treeview of the designer form will resemble the following:

    4. Click OK to close the C1TreeView Design Form dialog box.

    In Source View

    Add the following markup between the <cc1:C1TreeViewNode> tags of the node to which you wish to add the child node:

    Markup
    Copy Code
    <Nodes>
        <cc1:C1TreeViewNode ID="Node1" runat="server" Text="Node1">
        </cc1:C1TreeViewNode>
    <Nodes>
    

    In Code View

    Complete the following steps:

    1. Import the following namespace into your project:

      To write the code in Visual Basic:

      Visual Basic
      Copy Code
      Imports C1.Web.Wijmo.Controls.C1TreeView

      To write the code in C#:

      C#
      Copy Code
      using C1.Web.Wijmo.Controls.C1TreeView;
    2. Add the following code to the Page_Load event:

      To write the code in Visual Basic:

                     
      Visual Basic
      Copy Code

      ' Create first node and add it to the C1TreeView.
      Dim C1TreeViewNode1 As New C1TreeViewNode()
         C1TreeViewNode1.Text = "C1TreeViewNode1"
         C1TreeView1.Nodes.Add(C1TreeViewNode1) 

      ' Create the child node and add it to C1TreeViewNode1
      Dim C1TreeViewNode2 As New C1TreeViewNode()
         C1TreeViewNode2.Text = "C1TreeViewNode1"
         C1TreeViewNode1.Nodes.Add(C1TreeViewNode2)

      To write the code in C#:

      C#
      Copy Code

      // Create first node and add it to the C1TreeView.
      C1TreeViewNode C1TreeViewNode1 = new C1TreeViewNode();
      C1TreeViewNode1.Text = "C1TreeViewNode1";
      C1TreeView1.Nodes.Add(C1TreeViewNode1);

      // Create the child node and add it to C1TreeViewNode1
      C1TreeViewNode C1TreeViewNode2 = new C1TreeViewNode();
      C1TreeViewNode2.Text = "C1TreeViewNode2";
      C1TreeViewNode1.Nodes.Add(C1TreeViewNode2);

    3. Run the program.
    See Also