• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

Moving Selected Data From Listbox1 to Listbox2

Hello Experts,

I want to move some of the results of a query displayed in Listbox1 to Listbox2. I'm only wanting the SELECTED items from Listbox1 (a multiselect listbox) to go to Listbox2.

The code I'm using is putting the correct number of rows but inserting "System.Data.DataRowView" instead of the actual text from Listbox1. Usually I use SelectedValue when dealing with query results but that fails also. I've also tried SelectedIndices but that was a failure too. I've also added .ToString but that failed as well.

Here's my code:

 Dim i As Integer
        For i = 0 To Listbox1.SelectedItems.Count - 1
           Listbox2.Items.Add(Listbox1.SelectedItems.Item(i))
        Next i

Any help would be appreciated,

JackW
0
JackW9653
Asked:
JackW9653
  • 2
1 Solution
 
LIONKINGCommented:
Give this a try:

 Dim i As Integer
        For i = 0 To Listbox1.SelectedItems.Count - 1
           Dim myRv as DataRowView=Listbox1.SelectedItems.Item(i)
           Listbox2.Items.Add(myRv(0).ToString()) ' -->> Adjust for the column you want
        Next i
0
 
LIONKINGCommented:
If you can't do an implicit conversion, try a direct cast.

Dim i As Integer
        For i = 0 To Listbox1.SelectedItems.Count - 1
           Dim myRv as DataRowView=DirectCast(Listbox1.SelectedItems.Item(i), DataRowView)
           Listbox2.Items.Add(myRv(0).ToString()) ' -->> Adjust for the column you want
        Next i
0
 
JackW9653Author Commented:
Thank you very much, it worked perfectly.

JackW9653
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now