Click here to Skip to main content
13,446,125 members (36,293 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 15 Aug 2011

Difference between ListBox and CheckedListBox DataBinding

, 15 Aug 2011
Rate this:
Please Sign up or sign in to vote.
The difference between ListBox and CheckedListBox DataBinding.

Thought I would post this tip as it took me a little while to find the answer.

I had sucessfully bound my custom collection class to a ListBox control on a WinForm. However, when I attempted to bind to a CheckedListBox, it was populated with what appeared to be the ToString method of the collection's items, instead of the property specified for the DisplayMember.

I had read previously ([^]) that it is more efficient to set the DisplayMember and ValueMember properties before settings the DataSource property. Doing so prevents control refreshes.

However, a CheckedListBox does not display correct values unless the DataSource is set first.


With ListBox1
  .DataSource = Nothing
  .DisplayMember = "Source"
  .ValueMember = "Destination"
  .DataSource = MyCollection
End With

With CheckedListBox1
  .DataSource = Nothing
  .DataSource = MyCollection
  .DisplayMember = "Source"
  .ValueMember = "Destination"
End With

Hope this saves someone some time!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Engineer Computer Station (Cymru) Ltd.
United Kingdom United Kingdom
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 5 Wow, that is a subtle problem. Thank... Pin
Walt Fair, Jr.15-Aug-11 13:24
subeditorWalt Fair, Jr.15-Aug-11 13:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180314.2 | Last Updated 15 Aug 2011
Article Copyright 2011 by Paul_Williams
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid