locked
Cannot see the tree RRS feed

  • Question

  • User869548786 posted

    Hi,

    I created a treeview dynamically at the page load event as below

    TreeView t1 = new TreeView();
                TreeNode rootnode = new TreeNode();
                rootnode.Text = "root";
                t1.Nodes.Add(rootnode);


    When I execute the application I cant see anything

    Why? What am I missing.

    Further I would like to add a checkbox to the treeview.

    When I cant even see the tree, how will i add the checkbox

    Any ideas where am i going wrong.


    Regards

    cmrhema

    Thursday, November 26, 2009 8:44 PM

Answers

  • User1696475319 posted

    In the original case, I beleive it wasn't showing up because you weren't adding the treeview itself to the page Controls().

    As for the checkboxes, you can have a look at the TreeView.CheckedNodes property which returns the checked treeview items in a collection.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2009 6:48 AM

All replies

  • User869548786 posted

    Hi,

    In the previous code which I have written, I did not place any treeview control on the design page.

    But after I place a control, I am able to view it.

    Is there any way of displaying a control without placing the control on the design page.

    Regards

    cmrhema


    Thursday, November 26, 2009 9:46 PM
  • User-1032358594 posted
    <asp:TreeView ID="MyTreeView" Runat="server">
      <Nodes>
        <asp:TreeNode Value="Child1" Expanded="True" Text="1">
          <asp:TreeNode Value="Grandchild1" Text="A" />
          <asp:TreeNode Value="Grandchild2" Text="B" />
        </asp:TreeNode>
        <asp:TreeNode Value="Child2" Text="2" />
        <asp:TreeNode Value="Child3" Expanded="True" Text="3">
          <asp:TreeNode Value="Grandchild1" Text="A" />
        </asp:TreeNode>
      </Nodes>
    </asp:TreeView>

     

    Thursday, November 26, 2009 10:35 PM
  • User869548786 posted

    Hi,

    I will be creating a treeview control dynamically with checkbox as below

    I am giving a snapshot of it, because I will be retrieving the values from database. Hence I have to go for a dynamc control and not a static control


                TreeNode rootnode = new TreeNode();
    rootnode.Text = "root";
    rootnode.ShowCheckBox = true;
    t1.Nodes.Add(rootnode);

    TreeNode subnode = new TreeNode();
    subnode.Text = "subnode";
    subnode.ShowCheckBox = true;
    rootnode.ChildNodes.Add(subnode);

    TreeNode subnode1 = new TreeNode();
    subnode1.Text = "subnode1";
    subnode1.ShowCheckBox = true;
    rootnode.ChildNodes.Add(subnode1);



    Now the user will check anyof the boxes.

    I want to retreive all the selected checkboxes in treeview

    How do I do that.

    Anyone Pls.


    Regards

    cmrhema

    Sunday, November 29, 2009 6:33 AM
  • User1696475319 posted

    In the original case, I beleive it wasn't showing up because you weren't adding the treeview itself to the page Controls().

    As for the checkboxes, you can have a look at the TreeView.CheckedNodes property which returns the checked treeview items in a collection.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 29, 2009 6:48 AM
  • User869548786 posted

    Thanks Mendhak

    Got it

    string j = ";";
                if (t1.CheckedNodes.Count > 0)
                {
                    foreach (TreeNode tn in t1.CheckedNodes)
                    {
                        j = j + tn.Text;
                    }
                }


    Thanks again.

    Regards

    cmrhema

    Sunday, November 29, 2009 7:26 AM