473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1666

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
13
by: Gittyup | last post by:
Help please, We have a form, based on a query, that contains a listbox. The contents of the listbox are based on the results of the query. When the form is opened, the user selects an item...
2
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows...
3
by: Matthew Woods | last post by:
Hi, is there any way to format and order the columns displayed in a datagrid bound to a class that inherits from IBindingList? i have used DataGridTableStyle and added DataGridTextBoxColumns to it...
0
by: Clark Stevens | last post by:
I have an ArrayList (CAL) bound to a listbox (Listbox1). I want to delete an item in the ArrayList and reflect the changes back to the listbox. I have no problem deleting ArrayList items, but how...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
4
by: rn5a | last post by:
Can the items in a ListBox be sorted by the name of the items? The ListBox actually lists all directories & files existing in a directory on the server. Note that all the directories should be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.