Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
Binding to a Dataset
posted

I have a four table dataset that I am binding to my tree.  I have the relations set up and the tree displays as I would expect.  I had some issues setting a key and tag but put the following code in that seems to have sorted that part out.

void treeDocumentType_InitializeDataNode(object sender, InitializeDataNodeEventArgs e)
{
    switch (e.Node.BandName)
    {
        case "tblClass":
            e.Node.Key = ((DataRowView)e.Node.ListObject)["uidClass"].ToString();
            break;

        case "relClassMember":
            e.Node.Key = ((DataRowView)e.Node.ListObject)["uidMember"].ToString();
            break;

        case "relMemberSummary":
            e.Node.Key = ((DataRowView)e.Node.ListObject)["uidSummary"].ToString();
            break;

        case "relSummaryPhrase":
            e.Node.Key = ((DataRowView)e.Node.ListObject)["uidPhrase"].ToString();
            break;
    }
}

I suppose the first question is if this is the accepted way to set those variables or should I be doing something else.

The issue that I am having is reselecting a node after performing an operation.  I can easily re-bind the tree which work, but I can't make the previously selected node re-select.  I tried using

 treeDocumentType.GetNodeByKey(e.MemberId.ToString());

where e.MemberId is the Guid that was previously selected.  That result comes back as null.  However if I set a breakpoint and then open up the immediate window I can make the following query

?treeDocumentType.Nodes[0].Nodes[0].Key

this will show the correct key.  If I then re-execute the GetNodeByKey bit it will work.  Is there a better way to do this?

Thanks, I appreciate any insight.

Parents
No Data
Reply
  • 469350
    Offline posted

    indxlogic said:
    I suppose the first question is if this is the accepted way to set those variables or should I be doing something else.

    This is a good way to do it.

    indxlogic said:

    The issue that I am having is reselecting a node after performing an operation.  I can easily re-bind the tree which work, but I can't make the previously selected node re-select.  I tried using

     treeDocumentType.GetNodeByKey(e.MemberId.ToString());

    where e.MemberId is the Guid that was previously selected.  That result comes back as null.  However if I set a breakpoint and then open up the immediate window I can make the following query

    ?treeDocumentType.Nodes[0].Nodes[0].Key

    this will show the correct key.  If I then re-execute the GetNodeByKey bit it will work.  Is there a better way to do this?

    Thanks, I appreciate any insight.

    It's typically best to avoid re-binding the control if you can avoid it. Re-binding means that the whole tree, all the nodes, and all of the ColumnSets are destroyed and a whole new set are created. So this is very inefficient and you will lose the active node, the selected node, the width and position of the columns, etc.

    So my first question is - why rebind?

    To answer your question, the reason it's not working is that the tree loads the nodes as it needs them. So if you bind the tree and immediately call GetNodeByKey, the node you are looking for probably has not been added to the tree, yet. You can force the tree to load the nodes by looping through the nodes recursively and checking the Count property, but this isn't very efficient.

     

Children