Solved

Synchronising an arraylist with a checkedlistbox

Posted on 2010-11-20
4
521 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 1 month apart 11 35
VB.Net. Reading xml value 6 29
Visual studio 2015 1 21
what is the best Integrated development environment 2 20
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

839 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