468,110 Members | 1,846 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

listbox bound to arraylist no changing values when values in arraylist are added or deleted

Hi all,

I have a listbox that is complex bound by an arraylist. The problem is that
when I delete an object from the arraylist, the listbox does not reflect
those changes. I tried refreshing the listbox with no luck and, because it
is already bound, I can't just delete the item directly from the listbox
without an error (because it already has a datasource, you are not allowed
to delete/add anything to the listbox directly).

The application basically is doing nothing but a dual listbox populator
(values in the right listbox are sent to the left with an "add" or an "add
all" button - and vice-versa with "remove" and "Remove all"). Instead of
using datatables, it uses arraylists to keep track of objects. Because the
objects will ultimately contain more than 1 item, I can't do a simple
binding (I wish MS did not ruin the listbox).
If anyone has seen a dual listbox using arraylists (instead of datatables),
please post a link or code .

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 'returns an
arraylist of SalesRegionDD objects

lstRegionNames.DisplayMember = "reg_name"

lstRegionNames.ValueMember = "reg_idx"

lstRegionNames.DataSource = alRegionNames 'this listbox is bound to the
arraylist, so changes to the arraylist should reflect in the listbox, but
they do not!

lstSelectedRegionNames.DisplayMember = "reg_name"

lstSelectedRegionNames.ValueMember = "reg_idx"

End Sub

Private Sub Add() 'moves items from the right listbox to the left listbox

If lstRegionNames.SelectedIndex < 0 Then Return

Dim sr As New SalesRegionDD

sr = lstRegionNames.SelectedItem

Me.lstSelectedRegionNames.Items.Add(sr)

Me.TextBox1.Text = sr.reg_idx

Me.alRegionNames.Remove(sr)

End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click

Me.Add()

End Sub

Here is the SalesRegionDD class (DD stands for dropdown in case you were
wondering - this is reused in other parts of the app for dropdowns):

Public Class SalesRegionDD

Private _reg_idx As String

Private _reg_name As String

Public Sub New() 'nothing happens here, yet

End Sub

Public Property reg_idx() As String

Get

Return _reg_idx

End Get

Set(ByVal Value As String)

_reg_idx = Value

End Set

End Property

Public Property reg_name() As String

Get

Return _reg_name

End Get

Set(ByVal Value As String)

_reg_name = Value

End Set

End Property

End Class

If anyone has any insight on what I am doing wrong or if this is another MS
DotNet bug I am wasting my time chasing, please let me know. I've spent an
entire week trying to do a simple ping-pong dual listbox (driven by a
database) bound by arraylists.
A dual listbox is such a common item in DB apps, I can't believe that no one
has done one before in VB.Net (I spent an afternoon at the bookstore
looking for an example with no luck).

Help!

TIA

Dave
Nov 21 '05 #1
0 1412

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Vipin Kedia | last post: by
17 posts views Thread by amber | last post: by
13 posts views Thread by Gittyup | last post: by
2 posts views Thread by Luca | last post: by
3 posts views Thread by Matthew Woods | last post: by
reply views Thread by Clark Stevens | last post: by
18 posts views Thread by Dave Sauny | last post: by
7 posts views Thread by Dave | last post: by
4 posts views Thread by rn5a | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.