TreeView in ComboBox

10 posts, 0 answers
  1. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 29 Oct 2012 Link to this post

    I try to combine the example "TreeView in ComboBox" and "TreeView / Programmatic Data Binding"
    I use "BindToDataSet(ByVal treeView As RadTreeView)", but i only get  System.NullReferenceException.
    Tips on what the problem might be, or is there any example (vb) available?
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 31 Oct 2012 Link to this post

    Hello Kjell,

    I prepared a project that implements the functionality of both provided demos. ComboBoxItem and RadTreeView controls are created runtime and dynamically added to the RadComboBox object.  Please find the sample project attached to this response.

    Hope that this will lead you into right direction.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 31 Oct 2012 Link to this post

    Thanks, that works. But...
    How to get the selected node to display in the combobox like "TreeView / TreeView in ComboBox" exempel...
    And how to get RadComboBox1.SelectedValue from treeView.DataValueField on submit?
    I use RequiredFieldValidator to validate the TreeView, but i get I get the error message even though RadTreeView is selected...
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 01 Nov 2012 Link to this post

    Hello Kjell,

    I updated the sample project that I sent you in the last response in order to include the described functionality. I added a RadButton control that submits the RadComboBox selection on the client-side and pops up the selected text and value. You could also find RadTreeView OnClientNodeClickingand  and RadComboBox OnClientDropDownOpened client-side event handlers. 

    Please find the modifications explained below:

    //Code behind

    Private Shared Sub BindToDataSet(treeView As RadTreeView)
           .......
            treeView.DataValueField = "ID"
            .....
        End Sub
     
     
    Private Shared Sub ComboBoxBind(comboBox As RadComboBox)
            ......
            treeView.ID = "RadTreeView1"
            treeView.OnClientNodeClicking = "nodeClicking"
           ......
        End Sub

    I hope that you will find this helpful.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 08 Nov 2012 Link to this post

    Thanks. A question to ....
    I use AutoPostBack="true" because I want to save the value in a database.
    But after PostBack drop RadComboBox the tree, RadComboBox is empty.
    I want it to work like the example "TreeView / TreeView in ComboBox" after PostBack
    The selected node is selected after PostBack....
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 13 Nov 2012 Link to this post

    Hello Kjell,

    I have modified the sample project in order to cover your last requirement. I have added some client-side functionality and hidden input field that keeps the selected node text value. This way we keep track of the last selected node before the post-back.

    I hope that this would be helpful.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  8. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 18 Nov 2012 Link to this post

    Thanks for all help.
    One small problem remains for me, in the example I can save RadComboBox1.Text after x number of postback, but I lose RadComboBox.SelectedValue after one postback.
    Guess it's value in OnClientDropDownOpenedHandler that determines it, but my knowledge of the function is not good enough;-)
    So I'm hoping for some help again ....
  9. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 21 Nov 2012 Link to this post

    Hello Kjell,

    An easy and convenient way to keep track of the combo box selected value would be to store the selected item value to different hidden field on the page and on each page load to retrieve that value and apply it to the RadComboBox control as follows.

    function pageLoad() {
                var comboBox = $find("<%= RadComboBox1.ClientID %>");
                var comboValue = document.getElementById("treeNodeValue").value;
                comboBox.set_value(comboValue);
                console.log(comboBox.get_value());
            }
     
    Hope that you will find it helpful.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  10. Kjell
    Kjell avatar
    203 posts
    Member since:
    May 2011

    Posted 21 Nov 2012 Link to this post

    I get a Javascript error...
    Dump.
  11. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 23 Nov 2012 Link to this post

    Hello Kjell,

    I modified the project so that the SelectedValue property is updated on each button click as well as  persisted after post-back. I have already responded to the support ticket regarding the same problem, so my suggestion is to continue the discussion there.

    All the best,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017