Treeview questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DBC User

    Treeview questions

    I am trying to build a tree like the following

    Root
    |--- Current
    |-------- Date1
    |-------- Date2
    etc.,

    First I create the root, then make the root as the selected node and
    create Current and add it to the selected node. That is fine. Now I
    make the Current as selected node, but, it comes back null. I am using
    the following code, does anyone know why would the selected node
    comeback null??

    Thanks.

    treeView3.Nodes .Clear();
    treeView3.Nodes .Add(tRoot, tRoot); //tRoot = 'Root' string
    treeView3.Expan dAll();
    treeView3.Selec tedNode = treeView3.Nodes[tRoot];
    TreeNode cnode = new TreeNode();
    cnode.Text = currentRoot; //currentRoor = 'Current' string
    cnode.Name = currentRoot;
    treeView3.Selec tedNode.Nodes.A dd(cnode);

    //get treq, it is a database query to fetch all matching
    rows
    if (tReq.AnyRowAva ilableAll())
    {
    tReq.Rewind();
    do
    {
    treeView3.Selec tedNode =
    treeView3.Nodes[currentRoot];
    if (treeView3.Node s[tReq.AName] == null)
    {
    TreeNode node = new TreeNode();
    node.Text = tReq.AName;
    node.Name = tReq.AName;
    treeView3.Selec tedNode.Nodes.A dd(node);
    node = null;
    }
    } while (tReq.MoveNext( ));
    }

  • Peter Thornqvist

    #2
    Re: Treeview questions

    You don't need to use the selected node. This should work just as well:

    TreeNode ANode;
    treeView1.Nodes .Clear();
    ANode = treeView1.Nodes .Add("Root");
    ANode = ANode.Nodes.Add ("Current");
    if (tReq.AnyRowAva ilableAll())
    {
    tReq.Rewind();
    do
    {
    ANode.Nodes.Add (tReq.AName, tReq.AName);
    } while (tReq.MoveNext( ));
    }

    --
    Regards, Peter


    Comment

    Working...