Taking 2 listboxes (ListBox1 and ListBox2) with listbox2 containing items.
I can populate listbox1 with the contents of listbox2 using:
This of course populates listbox1 with the items in listbox2
What I thought would be just as easy a solution. I wanted to only add the selectedItems so I tried:
ListBox1.Items.AddRange(ListBox2.SelectedItems)where I was then given the error:
'Public Sub AddRange(items() As Object)': Value of type 'System.Windows.Forms.ListBox.SelectedObjectCollection' cannot be converted to '1-dimensional array of Object'.
'Public Sub AddRange(value As System.Windows.Forms.ListBox.ObjectCollection)': Value of type 'System.Windows.Forms.ListBox.SelectedObjectCollection' cannot be converted to 'System.Windows.Forms.ListBox.ObjectCollection'. C:\Users\Charlie\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 5 9 WindowsApplication1
I guess where I'm confused is why the SelectedObjectCollection cannot be converted to ObjectCollection. Wouldn't the first just be a subset of the objectcollection?
I did find a solution where I didn't have to create a loop (found not discovered />/>)
Here is the code that allows it to happen
So can someone enlighten me on what I'm apparently missing here? I understand the solution basically wraps the selecteditems to an array but I fail to understand why it is necessary.
This post has been edited by CharlieMay: 28 March 2013 - 06:51 PM