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

ListBox Remove Items

2 Answers 203 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Mathew
Top achievements
Rank 1
Mathew asked on 24 Feb 2011, 12:21 AM
Can someone post how to remove all items from a RadListBox?  This below code in the cs file doesn't work.

 

foreach (RadListBoxItem item in RadListBox1.Items)

 

 {

 

    item.Remove();

 

    //RadListBox1.Items.Remove(item);

}

My (hopefully temporary) workaround for this is that I create an empty DataSet and rebind that to the RadListBox.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Feb 2011, 08:26 AM
Hello Mathew,

Try the following code to achieve the same.
C#:
for (int i = RadListBox1.Items.Count-1; i >= 0; i--)
      {
          RadListBox1.Items.Remove(RadListBox1.Items[i]);
      }

Thanks,
Shinu.
0
Mathew
Top achievements
Rank 1
answered on 25 Feb 2011, 04:34 PM
That works.  Thanks Shinu!
Tags
ListBox
Asked by
Mathew
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mathew
Top achievements
Rank 1
Share this question
or