How to select tree item inside a RadComboBox

3 posts, 0 answers
  1. Vicenc Masanas
    Vicenc Masanas avatar
    38 posts
    Member since:
    Jul 2007

    Posted 06 May 2011 Link to this post

    I have a treeview inside a RadComboBox. I can set the selected node by using this code:
    tree.SelectedNodes.Clear();
     
    RadTreeNode node = tree.FindNodeByValue(idtema.ToString());
    if (node != null)
    {
        node.Selected = true;
    }

    And it works fine. The only problem is that the combo does not display the selected node.
    If I expand the combo I see it has the correct node selected, but I want it to be shown on the top, when the combo is closed.
    How can this be done?

    Thank you.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 May 2011 Link to this post

    Hello Vicenc,

    Try the following approach in the OnClientLoad event

    Javascript:
    <script type="text/javascript">
        function ClientLoad(sender)
         {
            var comboBox = sender;
            var tree = comboBox.get_items().getItem(0).findControl("RadTreeView1");
            var node = tree.findNodeByText("MyText");
            node.set_selected(true);
            var selectedNode = tree.get_selectedNode();
            if (selectedNode)
            {
                comboBox.set_text(selectedNode.get_text());
            }
        }
    </script>

    Hope it helps.

    Thanks,
    Princy.
  3. Vicenc Masanas
    Vicenc Masanas avatar
    38 posts
    Member since:
    Jul 2007

    Posted 06 May 2011 Link to this post

    Great that was exactly what I needed. Thank you.
Back to Top