?
Solved

Synchronising an arraylist with a checkedlistbox

Posted on 2010-11-20
4
Medium Priority
?
536 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Progress
Introduction to Processes
Suggested Courses

764 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