I have a CheckedListBox control whose DataSource is bound to an ArrayList.
I'm trying to persist the checked state of the items in the list box across
invocations of my application. Serializing the data to disk when the
application closes works just fine. However, when I try to re-set the
checked state of the items in the CheckedListBox in my Form's constructor,
nothing happens:
public class Form1 : System.Windows.Forms.Form
{
ArrayList AllItems;
CheckedListBox myCheckedListBox;
// etc...
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// Create an array list for all the user's items, and populate the
list with stuff saved in IsolatedStorage:
this.AllItems = new ArrayList();
this.IsoStorage = IsolatedStorageFile.GetUserStoreForAssembly();
PopulateCollection(); // fill the AllItems collection by loading any
saved items from IsolatedStorage.
// bind the AllItems collection to the CheckedListBox control:
myCheckedListBox.DataSource = this.AllItems;
// re-apply CheckState.Checked to any items that need it:
UpdateCheckBoxes();
}
private void UpdateCheckBoxes() {
foreach(Item I in AllItems)
{
if(I.checked == true)
{
int index = myCheckedListBox.IndexOf(I);
myCheckedListBox.SetItemChecked(index, true);
}
}
}
// the rest of Form1...
}
When I step through this in the debugger, everything seems to go exactly as
expected. In UpdateCheckBoxes( ) I can see that the right items have their
'checked' property set to true, and when myCheckedListBox.SetItemChecked( )
executes, I can see the count increase on the
myCheckedListBox.CheckedIndexCollection. It all looks like it's working
perfectly, but when the form actually appears on the screen, nothing is
checked. WTF?

Signature
I may not always have the best answers, but at least I'm not posting
questions in the wrong newsgroups...
Marcos Stefanakopolus - 31 Mar 2005 02:05 GMT
Gah. After posting this I saw a message on another thread that had the
answer and workaround. Sorry for the spam...

Signature
I may not always have the best answers, but at least I'm not posting
questions in the wrong newsgroups...
>I have a CheckedListBox control whose DataSource is bound to an ArrayList.
>I'm trying to persist the checked state of the items in the list box across
[quoted text clipped - 50 lines]
> working perfectly, but when the form actually appears on the screen,
> nothing is checked. WTF?
M.E - 27 Apr 2005 16:16 GMT
Well????? what threat u find??
From http://www.developmentnow.com/g/30_2005_3_0_0_372507/CheckedListBox-wont-check.ht