PC Review


Reply
Thread Tools Rate Thread

How to delete selected items in a ListBox

 
 
SeeBee
Guest
Posts: n/a
 
      9th Dec 2003
This must be easy but I can't get i right.

I have two listboxes, one to the left and on to the right.
The user can add items to the right one be selecting any
items in the left list and press an add button.
This will trigger an action to copy the items to the
listobx to the right:

selCol = LeftListBox.SelectedItems
outCol = RightListBox.Items
For i = 0 To selCol.Count - 1
If Not outCol.Contains(selCol(i)) Then
RightListBox.Items.Add(selCol.Item(i))
End If
Next

This works great. But I also like to be able to select any
items in the right ListBox and remove them by pressing
a "remove-button". I can't get this right though. I've
tried with this code but it obviosly doesn't work:

selCol = RightListBox.SelectedItems
outCol = RightListBox.Items
For i = 0 To outCol.Count - 1
If selCol.Contains(outCol(i)) Then
RightListBox.Items.RemoveAt(i)
End If
Next

Any ideas? Thanks in advance



 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      9th Dec 2003
* "SeeBee" <(E-Mail Removed)> scripsit:
> This works great. But I also like to be able to select any
> items in the right ListBox and remove them by pressing
> a "remove-button". I can't get this right though. I've
> tried with this code but it obviosly doesn't work:
>
> selCol = RightListBox.SelectedItems
> outCol = RightListBox.Items
> For i = 0 To outCol.Count - 1
> If selCol.Contains(outCol(i)) Then
> RightListBox.Items.RemoveAt(i)
> End If
> Next
>


\\\
Do While Me.ListBox1.SelectedIndices.Count > 0
Me.ListBox1.Items.RemoveAt(Me.ListBox1.SelectedIndices(0))
Loop
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
SeeBee
Guest
Posts: n/a
 
      10th Dec 2003

Thanks a lot! It seems to work perfect - great!

>-----Original Message-----
>* "SeeBee" <(E-Mail Removed)> scripsit:
>> This works great. But I also like to be able to select

any
>> items in the right ListBox and remove them by pressing
>> a "remove-button". I can't get this right though. I've
>> tried with this code but it obviosly doesn't work:
>>
>> selCol = RightListBox.SelectedItems
>> outCol = RightListBox.Items
>> For i = 0 To outCol.Count - 1
>> If selCol.Contains(outCol(i)) Then
>> RightListBox.Items.RemoveAt(i)
>> End If
>> Next
>>

>
>\\\
>Do While Me.ListBox1.SelectedIndices.Count > 0
> Me.ListBox1.Items.RemoveAt(Me.ListBox1.SelectedIndices

(0))
>Loop
>///
>
>--
>Herfried K. Wagner [MVP]
><http://www.mvps.org/dotnet>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning selected items in a listbox into another listbox DShikotra Webmaster / Programming 0 8th Jan 2008 03:25 PM
Listbox move multiple selected items to second listbox K B Microsoft ASP .NET 2 8th Jan 2007 12:16 PM
RE: delete multiple selected items from listbox =?Utf-8?B?UmFpbmJvdzAx?= Microsoft Access VBA Modules 4 27th Nov 2006 05:07 AM
How to use selected items from Listbox gerard.kompier@shell.com Microsoft Excel Programming 4 7th Apr 2006 05:02 PM
selected items at the top of the listbox =?Utf-8?B?Sm9obg==?= Microsoft ASP .NET 2 16th Mar 2006 12:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 PM.