0

I try the foll. code---

protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i <= ListBox1.Items.Count - 1; i++)
{
ListBox1.Items.Remove(ListBox1.SelectedValue.ToString());
}


}

But it's not working.

Edited by happygeek: fixed formatting

2
Contributors
3
Replies
6
Views
9 Years
Discussion Span
Last Post by Jx_Man
0

this section for vb.net but this following code will help :

protected void Button1_Click(object sender, EventArgs e)
{
while (listBox1.SelectedItem != null)
   {
      listBox1.Items.Remove(listBox1.SelectedItem);
   }
}
0

Or you can try this, but this following code not working in .net 1.1 :

public void RemoveItem()
{
   for (int i = 0; i < listBox1.Items.Count; i++)
   {
      if (listBox1.Items[i].Selected)
      {
         listBox1.Items[i].Selected = false;
         listBox1.Items.RemoveAt(i);
         RemoveItem();
      }
   }
}
0

Also u can try this foll code too :

while (listBox1.SelectedItems.Count > 0)
{
     listBox1.Items.Remove(listBox1.SelectedItems[0]);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.