Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / April 2005

Tip: Looking for answers? Try searching our database.

CheckedListBox won't check!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marcos Stefanakopolus - 31 Mar 2005 00:42 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.