RADTREEVIEW IN RADCOMBOBOX

10 posts, 1 answers
  1. Sanjay
    Sanjay avatar
    11 posts
    Member since:
    May 2009

    Posted 02 Sep 2009 Link to this post

    Hello,

    I am having hard time to code for RadTreeView in a RadComboBox. I am using VB.NET. I cannot see the RadTreeView instance at all
    from the code behind. Even if I try the FindControl method! I have to dynamically populate the treenodes with data from SQL Server

    ASPX code:
    <span><telerik:RadComboBox ID="ddDocType" runat="server" Width="200px" ShowToggleImage="True" Style="vertical-align: middle;" >
        <ItemTemplate>
            <div id="div1">
        <telerik:RadTreeView ID="rtvDocType" runat="server" Width="300px" Height="250px">
            <DataBindings>
                <telerik:RadTreeNodeBinding Expanded="True" />
            </DataBindings>
        </telerik:RadTreeView>
            </div>
        </ItemTemplate>
    </telerik:RadComboBox></span>

    VB.NET code:

     

     

    Dim tvDoc As RadTreeView = New RadTreeView()

     

    tvDoc =

    CType(FindControl("rtvDocType"), RadTreeView)

     

    tvDoc.Nodes.Clear()

     

     


    Here tvDoc gives a ERROR 'NullReferenceException'

    How can I make it work. Is there any working example where the Nodes are dinamically added from code behind for the RadTreeView
    in a RadComboBox?

    Thanks,
    Sanjay

     

  2. Denis
    Denis avatar
    5 posts
    Member since:
    Oct 2008

    Posted 02 Sep 2009 Link to this post

    Hello Sanjay
    Try to use

    Dim tvDoc As RadTreeView = New RadTreeView()

     

    tvDoc = CType(FindControl("rtvDocType"), ddDocType.Items(0))

     

    Denis

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sanjay
    Sanjay avatar
    11 posts
    Member since:
    May 2009

    Posted 02 Sep 2009 Link to this post

    Hi Denis,

    I tried: tvDoc = CType(FindControl("rtvDocType"), ddDocType.Items(0))
    but gives error: 
    Error 22 Type 'ddDocType.Items' is not defined.
    For the 0 in argument it says:
    Error 23 Array bounds cannot appear in type specifiers.

    Since I have ItemTemplate in aspx code, I also tried CType(FindControl("rtvDocType"), ddDocType.ItemTemplate(0))
    But same errors

    Please help. Maybe an example in your library with vb.net code will be helpful!

    Thanks,
    Sanjay
  5. Denis
    Denis avatar
    5 posts
    Member since:
    Oct 2008

    Posted 02 Sep 2009 Link to this post

    Yes it's normal. I've forget to mention that you have to add the following section after the itemtemplate of your RadCombo :

    <Items>  
    <telerik:RadComboBoxItem Text="" />  
    </Items>

    Denis

  6. Sanjay
    Sanjay avatar
    11 posts
    Member since:
    May 2009

    Posted 02 Sep 2009 Link to this post

    Hi Denis,

    Sorry after adding the block:
    <Items>  
    <telerik:RadComboBoxItem Text="" />  
    </Items> 

    I get the same error!

    My new block below:

     

    <telerik:RadComboBox ID="ddDocType" runat="server" Width="200px" ShowToggleImage="True" Style="vertical-align: middle;" >

     

     

    <ItemTemplate>

     

     

    <telerik:RadTreeView ID="rtvDocType" runat="server" Width="300px" Height="250px">

     

     

    <DataBindings>

     

     

    <telerik:RadTreeNodeBinding Expanded="True" />

     

     

    </DataBindings>

     

     

    </telerik:RadTreeView>

     

     

    </ItemTemplate>

     

     

    <Items>

     

     

    <telerik:RadComboBoxItem Text="" />

     

     

    </Items>

     

     

    </telerik:RadComboBox>

    Please help...

    Thanks,
    Sanjay

    Sanjay

     

  7. Answer
    Denis
    Denis avatar
    5 posts
    Member since:
    Oct 2008

    Posted 03 Sep 2009 Link to this post

    Hello Sanjay,

    I'm a beginner in telerik and use to program in c#. Here is a working sample :

    aspx source :
    <script type="text/javascript">
            function ApplicationNodeClicking(sender, args)
            {
                var comboBox = $find("<%= RadComboBoxApplications.ClientID %>");
                var node = args.get_node()
                comboBox.set_text(node.get_text());
                comboBox.trackChanges();
                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)
            {
    //            var tree = sender.get_items().getItem(0).findControl("RadTreeViewApplications");
    //            var selectedNode = tree.get_selectedNode();
    //            if (selectedNode)
    //            {
    //                selectedNode.scrollIntoView();
    //            }
            }
        </script>
    <div>
            <telerik:RadComboBox ID="RadComboBoxApplications" runat="server" ShowToggleImage="True" Style="vertical-align: middle;" OnClientDropDownOpened="OnClientDropDownOpenedHandler" EmptyMessage="Choose an application" oninit="RadComboBoxApplications_OnInit">
            <ItemTemplate>            
                <div id="div1">
                <telerik:RadTreeView  ID="RadTreeViewApplications" ShowLineImages="false"  runat="server" CheckBoxes="true"  OnClientNodeClicking="ApplicationNodeClicking"  >        
                </telerik:RadTreeView>        
                </div>
            </ItemTemplate>
            <Items>  
                <telerik:RadComboBoxItem Text="" />  
            </Items>         
            </telerik:RadComboBox>        
        </div>

    <script type="text/javascript">
            var divitem = document.getElementById("div1");
            if(null!=divitem)
                divitem.onclick = StopPropagation;
        </script>

    .cs source:

      private void bindApplicationsTree(ref RadTreeView objtree)
            {
                SqlConnection sqlConnection =new SqlConnection("a connection string");
                SqlCommand sqlCommand = new SqlCommand("select applicationid,applicationname from TApplications",sqlConnection);
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
                sqlConnection.Open();
                DataSet dsApplications = new DataSet();
                sqlDataAdapter.Fill(dsApplications);
                sqlConnection.Close();
                sqlDataAdapter.Dispose();
                objtree.DataValueField = "ApplicationID";
                objtree.DataTextField = "ApplicationName";
                objtree.DataSource = dsApplications;
                objtree.DataBind();

            }

           

            protected void RadComboBoxApplications_OnInit(object sender, EventArgs e)
            {
                Response.Write("<p>combo init fired</p>");
                RadComboBox objCombo = ((RadComboBox) sender);
                RadTreeView objTree = (RadTreeView)objCombo.Items[0].FindControl("RadTreeViewApplications");
                if(null!=objTree)
                    bindApplicationsTree(ref objTree);
                else
                {
                    Response.Write("<p>Warning: Unable to find the tree</p>");
                }
            }

    I hope this help.


    Denis





  8. Denis
    Denis avatar
    5 posts
    Member since:
    Oct 2008

    Posted 09 Sep 2009 Link to this post

    Hello Sanjay,

    Any news about your problem ? I would appreciate some feedback.

    Denis
  9. Sanjay
    Sanjay avatar
    11 posts
    Member since:
    May 2009

    Posted 09 Sep 2009 Link to this post

    Hi Denis,

    I first got converted into VB.NET. That went fine.
    FOR SOME REASON  oninit="RadComboBoxApplications_OnInit"
    will do a postback and the selected treenode (radcombobox text) will be left blank.
    Then I removed it and let the javascript in the client side populate the value.

    Your last reply helped me more than the first two replies.

    Thanks,
    Sanjay


  10. Ednilson Martins
    Ednilson Martins avatar
    1 posts
    Member since:
    Mar 2010

    Posted 07 Feb 2011 Link to this post

    This code works fine. It help me a lot. Thank's
  11. Atul
    Atul avatar
    1 posts
    Member since:
    Jan 2013

    Posted 01 Jan 2013 Link to this post

    It shows only Child Node I want All the hierarchy
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017