locked
Setting selected value or tree node of Telerik RadTreeView RRS feed

  • Question

  • User965458141 posted

     I have a radtreeview nested within a radComboBox.  I need to be able to set the selected value or node but I keep getting an error that selected value/selected node is read-only.  Does anyone know a workaround?

    ASPX
    
    
    <script type="text/javascript">
    //code for major node clicking
        function nodeClicking(sender, args) {
            var comboBox = $find("<%= rdCboMajor.ClientID %>");
            var node = args.get_node()
            //get the text of the tree node
            comboBox.set_text(node.get_text());
    
            comboBox.trackChanges();
            //get value here
            comboBox.get_items().getItem(0).set_value(node.get_value());
            //comboBox.get_items().getItem(0).set_value(node.get_text());
            comboBox.commitChanges();
    
            comboBox.hideDropDown();
    
        }
    
     function StopPropagation(e) {
            if (!e) {
                e = window.event;
            }
    
            e.cancelBubble = true;
        }
    
        function OnClientDropDownOpenedHandler(sender, eventArgs) {
            //major comboBox/radTreeView
            var tree = sender.get_items().getItem(0).findControl("TreeView1");
            //minor comboBox/radTreeView
            var tree1 = sender.get_items().getItem(0).findControl("TreeView2");
            //major comboBox/radTreeView
            var selectedNode = tree.get_selectedNode();
            //minor comboBox/radTreeView
            var selectedNode1 = tree1.get_selectedNode();
            //major comboBox/radTreeView
            if (selectedNode) 
            {
                selectedNode.scrollIntoView();
            }
            //minor comboBox/radTreeView
            if (selectedNode1) 
           {
                selectedNode.scrollIntoView();
           }
        }
    </script>
    
    
     <telerik:RadComboBox ID="rdCboMajor" runat="server" ShowToggleImage="true" OnClientDropDownOpened="OnClientDropDownOpenedHandler"
                            EmptyMessage="~Please Select~" Width="450px" Height="200px">
                            <ItemTemplate>
                                <div id="divMajor">
                                    
                                   <telerik:RadTreeView ID="TreeView1" runat="server" Width="450px" OnClientNodeClicking="nodeClicking">
                                        <DataBindings>
                                            <telerik:RadTreeNodeBinding Expanded="true" />
                                        </DataBindings>
                                    </telerik:RadTreeView>
                                    
                                </div>
                            </ItemTemplate>
                            <Items>
                                <telerik:RadComboBoxItem Text="" />
                            </Items>
                        </telerik:RadComboBox>
    
    
    CODE - BEHIND
    private void LoadTreeViewMajor()
            {
                //treeView is nested inside radcombobox...need to find it dynamically so we can add the nodes to it
                RadTreeView tvMajor = (RadTreeView)rdCboMajor.Items[0].FindControl("TreeView1");
                //RadTreeView tvMinor = (RadTreeView)rdCboMinor.Items[0].FindControl("TreeView2");
    
                List<ToolboxFacade.TBDal.UwQualificationCategory> lstCategories = QualificationCodeQueries.GetAllCategories(authUser);
                //need to filter by type E (education)
                lstCategories = lstCategories.Where(x => x.QcatTypeCd == "E").ToList();
                //get list of qualification descriptions
                List<QualificationCodes> lstCodes = QualificationCodeQueries.GetAllQualificationCodes(authUser);
    
                List<QualificationCodes> lstQcodes = new List<QualificationCodes>();
                //create parent node
                RadTreeNode parentNode = new RadTreeNode();
    
                //create child node
                RadTreeNode childNode = new RadTreeNode();
                //loop through each category and get the qualification descriptions in each category
                foreach (ToolboxFacade.TBDal.UwQualificationCategory cat in lstCategories)
                {
                    parentNode = new RadTreeNode();
                    parentNode.Text = cat.Category;
                    parentNode.Value = cat.QcatId.ToString();
    
                    lstQcodes = lstCodes.Where(x => x.QcatId == cat.QcatId).OrderBy(x => x.QualificationDesc).ToList();
                    //loop through each qualification description and add to the parent node
                    foreach (QualificationCodes qc in lstQcodes)
                    {
                        childNode = new RadTreeNode();
                        childNode.Text = qc.QualificationDesc;
                        childNode.Value = qc.QcId.ToString();
                        parentNode.Nodes.Add(childNode);
                    }
                    //add each parent node to the tree view
                    tvMajor.Nodes.Add(parentNode);
                    //tvMinor.Nodes.Add(parentNode);
                }
    
    
     private void LoadTreeViewMinor()
            {
                //treeView is nested inside radcombobox...need to find it dynamically so we can add the nodes to it
                //RadTreeView tvMajor = (RadTreeView)rdCboMajor.Items[0].FindControl("TreeView1");
                RadTreeView tvMinor = (RadTreeView)rdCboMinor.Items[0].FindControl("TreeView2");
    
                List<ToolboxFacade.TBDal.UwQualificationCategory> lstCategories = QualificationCodeQueries.GetAllCategories(authUser);
                //need to filter by type E (education)
                lstCategories = lstCategories.Where(x => x.QcatTypeCd == "E").ToList();
                //get list of qualification descriptions
                List<QualificationCodes> lstCodes = QualificationCodeQueries.GetAllQualificationCodes(authUser);
    
                List<QualificationCodes> lstQcodes = new List<QualificationCodes>();
                //create parent node
                RadTreeNode parentNode = new RadTreeNode();
    
                //create child node
                RadTreeNode childNode = new RadTreeNode();
                //loop through each category and get the qualification descriptions in each category
                foreach (ToolboxFacade.TBDal.UwQualificationCategory cat in lstCategories)
                {
                    parentNode = new RadTreeNode();
                    parentNode.Text = cat.Category;
                    parentNode.Value = cat.QcatId.ToString();
    
                    lstQcodes = lstCodes.Where(x => x.QcatId == cat.QcatId).OrderBy(x => x.QualificationDesc).ToList();
                    //loop through each qualification description and add to the parent node
                    foreach (QualificationCodes qc in lstQcodes)
                    {
                        childNode = new RadTreeNode();
                        childNode.Text = qc.QualificationDesc;
                        childNode.Value = qc.QcId.ToString();
                        parentNode.Nodes.Add(childNode);
                    }
                    //add each parent node to the tree view
                    //tvMajor.Nodes.Add(parentNode);
                    parentNode.ToolTip = "Click to see subcategories";
                    tvMinor.Nodes.Add(parentNode);
                }
    
               
            }
    
    
    if (degreeType == DegreeTypes.Associates.ToString() || degreeType == DegreeTypes.Bachelors.ToString()
                        || degreeType == DegreeTypes.Masters.ToString() || degreeType == DegreeTypes.Doctorate.ToString()
                         || degreeType == DegreeTypes.StudyArea.ToString())
                    {
                        pnlCollege.Visible = true;
                        txtCcity.Text = jsEd.City;
                        txtCcompDate.Text = jsEd.CompletionDate.Value.ToShortDateString();
                        txtCschoolName.Text = jsEd.SchoolName;
                        txtCcountry.Text = jsEd.Country;
                        ddlCdegree.SelectedValue = jsEd.DegreeCd.ToString();
                        
                                           
     RadTreeView tvMajor = (RadTreeView)rdCboMajor.Items[0].FindControl("TreeView1");
    //NONE OF THESE METHODS WORK TO SET THE SELECTED VALUE                    
    //tvMajor.FindNodeByValue(jsEd.qcMajorId.ToString()).Selected = true;
                       // rdCboMajor.Items[0].Value = jsEd.qcMajorId.ToString();
                        //rdCboMajor.Items.FindItemByValue(jsEd.qcMajorId.ToString()).Selected = true;
                        //rdCboMajor.Items.FindItemByText(jsEd.Major).Selected = true;
    
                        //toggle visibility of panels
                        pnlHS.Visible = false;
                        pnlLicCert.Visible = false;
                        pnlAlt.Visible = false;
                    }
    


     

     

    Thursday, August 6, 2009 10:54 AM

All replies

  • User139541927 posted

    You can do something like this:

    RadTreeNode node = RadTreeView1.FindNodeByValue("SOMENODEVALUE");
                    if (node != null)
                    {
                        node.Selected = true;
                    }

    Wednesday, March 24, 2010 1:33 PM
  • User1973567581 posted

    thnx it works

    Monday, January 31, 2011 6:33 AM