Solved

Synchronising an arraylist with a checkedlistbox

Posted on 2010-11-20
4
534 Views
Last Modified: 2012-05-10
I am using an ArrayList in one of my classes to hold a collection of "People" objects. I am also using a CheckedListBox component on a form to present this collection of people on screen.

I have a button which adds a new person (from a set of input TextBoxes) to both the ArrayList and the CheckedListBox at the same time so as to keep them in synch.

My question -
Is there any way I can set the collection in the CheckedListBox to be the same as that in the ArrayList so that the two are automatically kept in synch?
0
Comment
Question by:Jedeye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34179674
I think you are already using the best approach. There are other more complicated approaches but this one is the simplest
0
 
LVL 13

Expert Comment

by:Corey2
ID: 34181952
If you use a bindinglist instead of an arraylist you can set the bindinglist as the datasource of the checkedlistbox.  Then you can add directly to the bindinglist only and the checkedlistbox should update automatically.  Arraylists won't work the same because they don't raise listChanged events
0
 

Author Comment

by:Jedeye
ID: 34182692
Hi Corey2
Your solution sounds as though it would be perfect - but I can't find any obvious way to add the bindinglist as the datasource of the checkedlistbox - I am probably missiing something - can you enlighten me?
0
 
LVL 13

Accepted Solution

by:
Corey2 earned 500 total points
ID: 34184004
You simply set the datasource property of the Checkedlistbox to your bindinglist. If your bindinglist is filled with a more complex object you may need to use the DisplayMember and ValueMember properties to have more control over the behavior


Dim BL as new bindinglist (of String)
Checkedlistbox1.datasource = bl

bl.add("One Fish")
bl.add ("Two Fish")
bl.add ("Red Fish")
bl.add ("Blue Fish")

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question