This is a migrated thread and some comments may be shown as answers.

Unexpected SelectedIndexChanged behavior

1 Answer 72 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 11 Feb 2009, 01:22 PM
Hi,
I am using a RadComboBox with an embedded RadTreeview. It is coded pretty much exactly as the samples were.
However I have AutoPostBack=True on the RadComboBox so I can catch the SelectedIndexChanged event on the server.
The only problem seems to be that the SelectedIndexChanged event does not happen until the RadCombo loses focus. I would like it to happen when the user selects an item in the treeview.
Below is the client side code I have attached to the combo.
Any help would be great.
Thanks ... Ed

function tvCombo_Load(sender, eventArgs)  
{  
    sender.set_text(sender.get_items().getItem(0).get_value());  
}  
function tvCombo_NodeClicking(sender, args)  
{  
    var node = args.get_node();  
    var tv = node.get_treeView();  
    var bLeavesOnly = tv.get_attributes().getAttribute("LeavesOnly");  
    var cboId = tv.get_attributes().getAttribute("cboId");  
 
    if (bLeavesOnly == "true") // they can only select leaves  
    {  
        // add in the following code as a condition to disable root nodes that are leaves from being selected   
        //  || node.get_parent().get_parent() == null  
        if (node.get_nodes().get_count() > 0)   
        {  
            args.set_cancel(true);  
            return;  
        }  
    }  
    var ddl = $find(cboId);  
    ddl.trackChanges();  
    ddl.set_text(node.get_text());  
    ddl.get_items().getItem(0).set_value(node.get_text());  
    ddl.commitChanges();  
    ddl.hideDropDown();  
}  
function tvCombo_StopPropagation(e)  
{  
    if (!e)  
        e = window.event;  
    e.cancelBubble = true;  
}  
function tvCombo_OnClientDropDownOpenedHandler(sender, eventArgs)  
{  
    var cboItem = sender.get_items().getItem(0);  
    var treeId = sender.get_attributes().getAttribute("tvId");  //cboItem.get_attributes().getAttribute("TreeId");  
    if (treeId)  
    {  
        var tv = cboItem.findControl(treeId);  
        var selectedNode = tv.get_selectedNode();  
          
        if (selectedNode)  
        {  
            // expand the parents  
            var oNode = selectedNode.get_parent();  
            while (oNode)  
            {  
                // can't expand the root's parent as it is the treeview itself  
                if(oNode.get_parent())  
                    oNode.expand();  
                oNodeoNode = oNode.get_parent();  
            }  
 
            selectedNode.scrollIntoView();  
        }  
    }  

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 13 Feb 2009, 04:52 PM
Hi Ed Staffin,

There is only one Item in the ComboBox in this example and the selection could not change because of the stopPropagation function.

I suggest you subscribe to the NodeClick server-side event of the TreeView to handle the case of clicking (selecting) a Node.

All the best,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ComboBox
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or