Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to make a button delete more than one item at the same time when they r all highlighted in a list box. Here's what I have so far:

 

Private Sub DelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DelButton.Click
       If LeftListBox.SelectedItems.Count <> 0 Then
           LeftListBox.Items.Remove(LeftListBox.SelectedItem)
           LeftTextBox.Focus()
           EnableDisableButtons()
       End If
       If RightListBox.SelectedItems.Count <> 0 Then
           RightListBox.Items.Remove(RightListBox.SelectedItem)
           LeftTextBox.Focus()
           EnableDisableButtons2()
       End If
   End Sub

 

Cheers

  • *Experts*
Posted
Dim item As Object

For Each item In LeftListBox.SelectedItems
 LeftListBox.Items.Remove(item)
Next

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • 2 months later...
Posted

Dim item As Object

For Each item In LeftListBox.SelectedItems
 LeftListBox.Items.Remove(item)
Next

 

Doen't works in C# because the SelectedItems collection changes while looping through wich causes an error, anybody knows how to do it with a short code??

 

(The only working way i know right know is: )

object[] aItems = new object[listBox1.SelectedItems.Count];
listBox1.SelectedItems.CopyTo(aItems, 0);

foreach(object oDelItem in aItems)
{
listBox1.Items.Remove(oDelItem);
}

Posted

------------------- Also -------------------

 

Seb

Newcomer

 

Registered: Nov 2003

Location:

Posts: 7

 

I've tried that but it only deletes one at a time in either list box.

 

12-03-2003 06:14 PM

 

------------AND----------------------------------------

 

Seb

Newcomer

 

Registered: Nov 2003

Location:

Posts: 7

HELP NEEDED!!

Anyone else have any ideas?

 

12-05-2003 06:33 PM

 

 

------------------------------------------------------------

 

19 minutes, isnt exactly a long time to leave it before you bump a thread. Leave a day or two in future, give people a chance to read your 'demands'.

 

Everyone here is very helpful, and will help you if they can - i have been helped to no-end myself. Just dont take the piss out of them.

Posted

while selecteditems is not nothing
   selecteditems.remove(0)
loop

 

won't work because selecteditems doesn't contains a remove function.. And if it has it would be more logic that it would only deselect the items.

Posted

for(int i = listBox1.SelectedItems.Count - 1; i >= 0; i--)listBox1.Items.Remove(listBox1.SelectedItems[0]);

 

Thanks sho, that was the code i was lookin for.. After all it is so simple i should have thought it myself...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...