This is a migrated thread and some comments may be shown as answers.

Problem With Auto Selecting Node

1 Answer 132 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 08 Jul 2014, 10:31 PM
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?


1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Jul 2014, 09:50 AM
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.

C#:
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;
                }
            }
        }
    }
}

Thanks,
Shinu.
Tags
DropDownTree
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or