Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to move multi Items from ListBox1 to ListBox2,
But I receive an error message that the below underlined is not a collection type!

What I have tried:

Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.ListItemCollection

For Each selectedItem In ListBox1.SelectedItem
            ListBox2.Items.Add(ListBox1.SelectedItem)
            ListBox1.Items.Remove(ListBox1.SelectedItem)
        Next
Posted
Updated 29-Aug-18 22:58pm

1 solution

ListBox1.SelectedItem is a single item, so you cannot use a For Each statement on it. You need to iterate the ListControl.Items Property (System.Web.UI.WebControls) | Microsoft Docs[^].
 
Share this answer
 
Comments
MicroPixel 30-Aug-18 6:42am    
Thank you Richard, still unclear to me! do you mean I cant use any other statements like for or while?
Richard MacCutchan 30-Aug-18 7:32am    
You can use any statements that you want; but only if they follow the correct syntax and usage. You could use an index (for or while) into the ListBox items, but For Each is much simpler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900