Problem With Auto Selecting Node

2 posts, 1 answers
  1. Mike
    Mike avatar
    74 posts
    Member since:
    Mar 2013

    Posted 08 Jul 2014 Link to this post

    I think I found a possible bug with the Drop Down Tree and setting the default selected value.  I followed this link I created a few months ago and just found this issue now.

    I have a tree that looks like this:
    - Grades          //ID: 0, Parent: null, Value: 0
    -- Random          //ID: 1, Parent: 0, Value: 2
    --- J          //ID: 2, Parent: 1, Value: 7
    --- Prime          //ID: 3, Parent: 1, Value: 8
    --- A          //ID: 4, Parent: 1, Value: 9
    --- 2 & Better          //ID: 5, Parent: 1, Value: 10
    --- 2          //ID: 6, Parent: 1, Value: 11
    --- Select          //ID: 7, Parent: 1, Value: 12
    -- Fixed          //ID: 8, Parent: 0, Value: 1
    --- J          //ID: 9, Parent: 8, Value: 1
    --- Prime          //ID: 10, Parent: 8, Value: 2
    --- A          //ID: 11, Parent: 8, Value: 3
    --- S          //ID: 12, Parent: 8, Value: 4
    --- Econ          //ID: 13, Parent: 8, Value: 5

    As you can see, there are duplicate text (I only allow the selection of the child elements - "Grades", "Random" and "Fixed" are not allowed as they are the root or are types).  So if I have:
    RadDropDownTree.SelectedValue = "2";
    RadDropDownTree.SelectedText = "Prime"
    and for some reason the "Prime" under "Random" is selected, when the "Prime" under "Fixed" SHOULD be selected.  Does that make sense?

    It appears that the SelectedText property selects the first text value that matches the input and does not respect the SelectedValue.  Is there a way I can fix this?

  2. Answer
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2014 in reply to Mike Link to this post

    Hi Mike,

    In order to select an node from the RadDropDownTree try to set either SelectedValue or SelectedText.  If you are setting both it will select the first item which matches the value/text. In your scenario first it will select the "Random" Item, because it's value is "2". After executing the next line of code it will change the selection to "Prime" Item inside the "Radndom" because in dropdown this coming at first. This is the expected behavior of the control. In order to achieve your scenario you have to loop through all the the nodes in the RadDropDownTree and select the node based on your requirement. Please have a look into the C# code snippet which works fine at my end.

    foreach (RadTreeNode rootNode in rdroptreeDemo.EmbeddedTree.Nodes)
        foreach (RadTreeNode parentNode in rootNode.GetAllNodes())
            if (parentNode.Text == "Fixed")
                foreach (RadTreeNode childNode in parentNode.GetAllNodes())
                    if (childNode.Value == "2")
                        childNode.Selected = true;

  3. DevCraft R3 2016 release webinar banner
Back to Top