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

Delete all items from ComboBox - javascript

4 Answers 191 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
CHRIS
Top achievements
Rank 1
CHRIS asked on 11 Oct 2011, 04:16 AM
I can add items to a comboBox - thru your excellent Telerik example.

But I am trying to delete all items , this code deletes some , not all 

function RemoveAllItems() 
    {
  
        var combo = $find('cboGarmentSize');
        var comboItems = combo.get_items();
          
        for (var i = 0; i < comboItems.get_count(); i++)
        {
            combo.trackChanges();
            var item = comboItems.getItem(i);
  
            combo.get_items().remove(item);
            combo.commitChanges();
              
        }
           
    }

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Oct 2011, 05:25 AM
Hello Chris,

Try the following modified code.
javascript:
function RemoveAllItems()
   {
       var combo = $find('RadComboBox2');
       var comboItems = combo.get_items();
       for (var i = comboItems.get_count()-1; i>=0 ; i--)
         {
           combo.trackChanges();
           var item = comboItems.getItem(i);
           combo.get_items().remove(item);
           combo.commitChanges();
         }
    }

Regards,
Shinu.
0
CHRIS
Top achievements
Rank 1
answered on 11 Oct 2011, 05:37 AM
Hi Shinu,

Fixed ,

I see you have to remove the items from the "top" of the array first.
Excellent work.

Cheers Chris,


0
Daniel Aquere
Top achievements
Rank 2
answered on 19 Feb 2014, 02:13 PM
Hi Shinu and everyone,

Please, how I delete all items with server side command?

Thanks, best
0
Daniel Aquere
Top achievements
Rank 2
answered on 19 Feb 2014, 02:20 PM
I found... 

Combobox.Items.Clear();

tks
Tags
ComboBox
Asked by
CHRIS
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
CHRIS
Top achievements
Rank 1
Daniel Aquere
Top achievements
Rank 2
Share this question
or