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

Programmatically setting item doesnt work

3 Answers 78 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 17 Mar 2008, 08:31 AM
Hi,

I am trying to accomplish what I thought was a relatively simple task - programmatically setting the selected item, and I cannot get it to work.

Prior to my user attempting to change the selection in the combobox, I have to check whether they are allowed to or not (they may not have filled in everything required for example), so I have hooked up the OnClientSelectedIndexChanging event and am checking if they can change the selection or not in this event.  If they are not allowed to change, I am saving the index of the item they requested, cancelling the selectionchanging event and prompting them.  If they choose a certain answer I wish to allow the new selection to be allowed so then try to select the index of the item they originally selected.  I have tried this the following ways:

pageList.set_selectedIndex( pageIndexToLoad );  
 
pageList.set_selectedItem( pageList.get_items().getItem( pageIndexToLoad ) );  
 

Both correctly set the selected index/item of the combobox, but neither actually change the combobox to the respective item - it is left displaying the original item.  What am I missing?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Jonathan
Top achievements
Rank 1
answered on 17 Mar 2008, 08:41 AM

As another comment, I can get this to work by using:

var pageList = $find( "ShowPageList" );       
var newItem = pageList.get_items().getItem( pageIndexToLoad );  
          
pageList.set_selectedItem( newItem );  
pageList.set_text( newItem.get_text() );  
 

So my question is really, why does setting the selected item not automatically update the combobox accordingly?

Thanks.
0
Accepted
Simon
Telerik team
answered on 19 Mar 2008, 02:22 PM
Hello Jonathan,

You could you use RadComboBoxItem.select() instead RadComboBox.set_selectedItem(), which is now obsolete. Please review the following code:

var pageList = $find( "ShowPageList" );        
var newItem = pageList.get_items().getItem( pageIndexToLoad );  
newItem.select(); 

This will successfully select the new item in the RadComboBox.

I hope this helps.

Greetings,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan
Top achievements
Rank 1
answered on 19 Mar 2008, 02:26 PM
Hi there,

Apologies, I didnt realise that the set_selectedItem method was obsolete.  It works perfectly with the new method.

Thanks again.
Tags
ComboBox
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Jonathan
Top achievements
Rank 1
Simon
Telerik team
Share this question
or