?
Solved

Problem with Multis Selct ListBox on Remove...

Posted on 2005-04-22
1
Medium Priority
?
193 Views
Last Modified: 2011-09-20
Me below code runs on lstListBox1_DoubleClick1 it's job is to move items from List one over to list 2
and then remove them from List1 so the user can not double select them. On a single select this code
works fine but if i do this with a multi select it trows an error saying "index is outside of the Bounds"
If i disable the remove command the code works fine


Dim i As Int32
        For i = 0 To lstListBox1.SelectedItems.Count - 1

            lstListBox2.Items.Add(lstListBox1.SelectedItems(i).ToString())
            lstListBox1.Items.Remove(lstListBox1.SelectedItems(i).ToString())
        Next
0
Comment
Question by:AlexPonnath
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 13848224
How about:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        While lstListBox1.SelectedItems.Count > 0
            lstListBox2.Items.Add(lstListBox1.SelectedItems(0).ToString())
            lstListBox1.Items.Remove(lstListBox1.SelectedItems(0).ToString())
        End While
    End Sub
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question