Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Problems with the Windows Forms Listbox (VB.NET 1.1)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Philip - 22 Feb 2007 15:22 GMT
Hi,

I have auser control with two listboxes on it. When the user selects one or
several items in the left box and clicks Add, they are copied into the
listbox on the right. When the user selects one or multiple items in the
listbox on the right (lstSelected) I want to remove the selected items.

I tried doing it like this (for one):
lstSelectedList.Items.Remove(lstSelectedList.SelectedIndex)

and it doesn't throw an error, but no items are removed.

What is wrong with my code?

Also, how do I code it so that if the user selects multiple items, they are
removed?

thanks

Philip
mangist@gmail.com - 23 Feb 2007 04:02 GMT
> Hi,
>
[quoted text clipped - 16 lines]
>
> Philip

The Remove() method expects the ListBoxItem object.  You are looking
for the RemoveAt() method which takes an index of the item.

On some button click (like 'Remove') you want this code:

Button_OnClick() {
 for (int i = lstSelectedItems.SelectedIndices.Count ; i >= 0; -- i )
{
    lstSelectedItems.RemoveAt (lstSelectedIndices[i]);
 }
}

(in C#, my VB isn't up to scratch)
Manish Bafna - 23 Feb 2007 04:07 GMT
Hi,
Try this code:

listBox1.Items.Remove(listBox1.SelectedItem);

Thanks and regards,
Manish Bafna.
MCP and MCTS.

> Hi,
>
[quoted text clipped - 16 lines]
>
> Philip

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.