How to display checked treeview nodesas combobox text?

4 posts, 0 answers
  1. Neha
    Neha avatar
    21 posts
    Member since:
    Jan 2011

    Posted 25 Jul 2011 Link to this post

    I was referring telerik demo for such functionality - http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx

    The only change is i am using treeview with checkbox in RadComboBox. I wanted to display checked items of combobox as comobobox text with comma on collapse.

    How to do that?
  2. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 25 Jul 2011 Link to this post

    Hi Neha,

    This should get you most of the way there.  It assumes that you only have one RadComboBoxItem where the ItemTemplate lives.

    I'm just typing this in the browser - so this code is not tested.  :-)

    function RadComboBox_OnClientDropDownClosing(sender, eventArgs) {
        var item = sender.get_items().getItem(0);// Get the first RadComboBoxItem
        var treeView = item.findControl('putTreeViewNameHere');// Find your RadTreeView
        var checkedNodes = treeView.get_checkedNodes();// Retrieve the checked items in the RadTreeView
     
        var newText = '';
        checkedNodes.forEach(function(node) {  // Loop through the checked nodes. Requires jQuery!
           if (newText != '') {newText += ', ';}
           newText += node.get_text();
        });
        sender.set_text(newText);// Set the RadComboBox text
        if ($.browser.msie) { // IE sometimes takes two tries for it to respond to new text
            sender.set_text(newText);
        }
    }

    Good luck!
    Thad
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Teoman
    Teoman avatar
    69 posts
    Member since:
    Jan 2009

    Posted 20 Sep 2011 Link to this post

    hi,
    i used your code.when i checked value first time in treeview there is no text in the combobox but when i click combobox again when it closed it shows me the values in combobox.?what can we the problem?
  5. Teoman
    Teoman avatar
    69 posts
    Member since:
    Jan 2009

    Posted 28 Feb 2012 Link to this post

    hi thad,

    can you help me about your code please!

    i am trying your code its working in chrome and firefox but its not working on ie.

    ie give js error at line 14

    Message: Object doesn't support this property or method
    Line: 14
    Char: 9
    Code: 0

    this is line which i get the error.

    checkedNodes.forEach(function (node) { // Loop through the checked nodes. Requires jQuery!
Back to Top