The first listbox cannot be updated directly as it is bound by the
arraylist.
So I remove an item from the arraylist that is tied to the first listbox,
but because the listbox is bound, I can't simply remove an item directly
from the listbox (if I try to remove anything directly from the listbox, I
get an error that basically says it is already bound - catch 22).
In other words:
say the bound listbox is called "lstRegionNames" and it is bound to the
arraylist "alRegionNames"
Private alRegionNames As New ArrayList
Private alSelectedRegionNames As New ArrayList
Private Sub form4_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
loadDBRegionNames()
End Sub
Private Sub loadDBRegionNames()
alRegionNames = SalesRegionsDB.GetRegionNamesActiveAL
'the first listbox bound to the arraylist
lstRegionNames.DisplayMember = "reg_name"
lstRegionNames.ValueMember = "reg_idx"
lstRegionNames.DataSource = alRegionNames
' the second listbox -
lstSelectedRegionNames.DisplayMember = "reg_name"
lstSelectedRegionNames.ValueMember = "reg_idx"
End Sub
Private Sub Add() 'called when clicking the Add button
If lstRegionNames.SelectedIndex < 0 Then Return 'if nothing selected,
exit sub
Dim sr As New SalesRegionDD 'the object which contains "reg_idx" and
"reg_name"
sr = lstRegionNames.SelectedItem
Me.lstSelectedRegionNames.Items.Add(sr) 'add the object to the second
listbox - this works fine
Me.alRegionNames.RemoveAt(lstRegionNames.SelectedI ndex) 'remove that object
from the arraylist - this works fine- I verified this by looping through the
objects in "alRegionNames" - the object was indeed removed from the
arraylist
'an attempt at refreshing the first listbox by re-binding it to the
arraylist - this does not refresh "lstRegionNames"
Me.lstRegionNames.DataSource = Me.alRegionNames
End Sub
I had done this with a datatable and removing an item from the datatable
removes it from the bound listbox automatically.
Doing the exact same thing with an arraylist does not work, though.
I don't know how to proceed or what else needs to be done to be able to
remove the item from "lstRegionNames"
"alejandro lapeyre" <al**************@jotmail.com> wrote in message
news:eA****************@TK2MSFTNGP10.phx.gbl...
What is so difficult in writing this control?
insert one lisbox
insert the buttons
insert other listbox
fill the first listbox
create an empty arraylist
when the user clicks the move here button
get the item using the listbox.selectedindex
remove from the collection, and the listbox.items
add it to the other collection and to the other listbox
I am missing something?
Alejandro Lapeyre
"MCDave" <daven(delete_this)@miraclecatDELETETHISTOO.com> escribió en el
mensaje news:Oa****************@TK2MSFTNGP12.phx.gbl... This image should clarify.
www.miraclecat.com/listbox2listbox.gif
MCDave