moving data in listbox

Signo.X

Well-known member
Joined
Aug 21, 2006
Messages
76
Location
Australia
Programming Experience
1-3
hello all ,

Ive got 2 list boxes, one is bind to a DB column , i.e. it reads data from column in an access db table.

the other list box i use to move selected items from the first list box.
example :

list_box1 list_box2
1 2
3

> >>

i have a button > to move one record at the time and >> to move all the records from box1 to list 2 at one hit.

i use the following when the user clicks on > :
ListBox2.Items.Add(ListBox2.Text)
it works fine , but then how do i remove the value from list_box1 so its only in list_box2?

when i try list_box1.items.removeat(index) it gives me an error :
Cannot modify the Items collection when the DataSource property is set

how can i remove it without any problems ??????

also , when the user clicks on >> , how do i copy all the items in list1 to list2???

I'm getting sick of this , i spend almost 4 hours trying different things to fix that problem... :mad:

please help!!

~Signo.X
 
If control is databound you have to modify its datasource, else you can choose to not bind it to datasource but instead add all the items manually from datasource and treat everything manually.
 
Don't attach a datasource to your listbox.
You will have to add the items manually to your listbox

For each item in datatable
lstbox1.items.add(item)
Next

lstbox1.displaymember = ...
lstbox1.valuemember = ...

Now you should be able to do whatever you want with them, and at the end you can save all items of lstbox2.
 
Thanks for the reply guys!!

it works, some times things are so simple to do but too complicated to apply!




!signo.X
 
Last edited:
Help

hi,
Could you please give the code..coz even i am facing the same problem.. and cant find the way out..

infact this is what i am doing
********************************
Dim dt As DataTable = ds.Tables(0)
Dim row As DataRow
For Each row In dt.Rows
lstContent.Items.Add(row(0))
Next
lstContent.ValueMember = dt.Columns(0).ToString
lstContent.DisplayMember = dt.Columns(1).ToString
**********************************
and for add button i have something like this

lstChannels.Items.Add(lstContent.Text)
lstContent.Items.Remove(lstContent.SelectedIndex)


Regards
 
Last edited:
Back
Top