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
1052
Xam
posted

Hi,

I have a XamDataTree with check boxes, with the check box mode set to auto, so the checks are propagation up/down and a node target with a CheckBoxMember path set.

I need to be able to reload the tree and have the previously check nodes still checked. So what I am doing is keeping track of the checked nodes then when I rebuild my collection of nodes I set the IsChecked property to true objects that match the previously selected.

My problem is when I bind this collection the correct nodes are checked but their parents will not show indeterminate etc.

I have included a simple example to try and show what I am doing.

Thanks

XamDataTree.zip
Parents
  • 21382
    posted

    Ok so there are two things which appear wrong with the way you are looking for your nodes in this sample:

    This first is that the FindNode method will exit out too early if it is not found in the first parent.

     

    The method is written as (or similar to)

     

    foreach

     

     

    (SimpleNode node in nodes)

    {

     

     

    if (node.Name == name)

     

     

    return node;

     

     

    return FindNode(node.Children, name);

    }

     

    You should not be returning from FindNode unless it found a matching node.  As written the foreach (SimpleNode in Nodes) loop would only look at the first member of any collection prior to exiting (found or unfound).  The loop should look more like

                

    foreach (SimpleNode node in nodes)
                {
                    if (node.Name == name)
                        return node;
                    SimpleNode nodex = FindNode(node.Children, name);
                    if (nodex != null)
                        return nodex;                     
                }

     

    Here the lower findNode calls have to actually return something to be seen as an exit case.

     

     

    The second thing I noticed was that with your data, your deeper levels of nodes would never be found when you are looking for the name of a string.  The second and third of data are the same for each parent node, so when you search for "Node 1-0" it will always find the "Node 1-0" under the "Node 0-0" and terminate. 

     

    If your IsChecked field is not persisted in a table or backing store, and you are recreating your data all the time, you would need to find a more unique way of identifing your data.  Now this could just be a sample issue, but its visible.

     

     

     

Reply Children