Question moving items in a listbox (filled from database) to 2nd listbox

nebakanezzar

Member
Joined
Apr 2, 2010
Messages
6
Programming Experience
Beginner
Hey All,

I am in need of a little help. I am populating a listbox from a database, and then i want to move the selected items to a 2nd listbox.

1 - the 1st listbox is populated with peoples first names from a database, this works fine.
2 - when i select the name(s) i wish to move, the button click event does not populate the 2nd listbox with the selected name(s), but rather "System.Data.DataRowView"

here is the code i am using for the button click.:

Dim intAdd As Integer
For intAdd = 0 To lstName.Items.Count - 1
If lstName.GetSelected(intAdd) = True Then
lstAdd.Items.Add(lstName.Items(intAdd))
End If
Next intAdd

My question is:

1 - how do i get the 2nd list box to show the selected name(s) from the 1st listbox? i assume i need to convert it somehow, but i am not sure how?

Side questions:

2 - in the database i have a field for first name, and a field for last name. i would like to use both fields to populate the 1st listbox, so the full name is displayed, if possible.

3 - optimally, i would like to use a checklistbox for the 1st listbox, but it seems there is no option to databind the checklistbox, and i am not sure how to code this. Is this possible? i have done some searching and googleing to no avail.

thanks

neb.
 
1. There are various things you could do depending on the exact result you want. The first thing is to confirm whether you actually want to MOVE the items from one list to the other, as the title suggests, or COPY the items to the second list, as the code suggests.

2. The ListBox can only display what's in its DataSource. If you want to combine the two names then you'll need to add a third column and populate it with the combined values, which you could do by setting its Expression property.

3. The CheckedListBox supports data-binding in exactly the same way as the ListBox, which it inherits. What it doesn't support is binding to the check boxes displayed on the items. It doesn't appear that you need that anyway.
 
1. There are various things you could do depending on the exact result you want. The first thing is to confirm whether you actually want to MOVE the items from one list to the other, as the title suggests, or COPY the items to the second list, as the code suggests.

I believe am looking to copy, the intent is to create new records based on the items selected from the 1st listbox.

2. The ListBox can only display what's in its DataSource. If you want to combine the two names then you'll need to add a third column and populate it with the combined values, which you could do by setting its Expression property.

Awesome, thanx!

3. The CheckedListBox supports data-binding in exactly the same way as the ListBox, which it inherits. What it doesn't support is binding to the check boxes displayed on the items. It doesn't appear that you need that anyway.

How does the checkedlistbox work? When i drag the the the field as a listbox from the 'data sources' window, there is a checkbox in the listbox for 'use data bound items'. this option is not available when i drag a field as a checkedlistbox from the 'data sources' window. so i was assuming the data binding had to be coded?

thanx for your advice.

Neb.
 
Back
Top