We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CheckedListbox not setting checked state

Thread ID:





3318 Mar 12,2003 07:46 PM UTC Mar 18,2003 03:36 PM UTC WinForms 2
Tags: Tools
Administrator [Syncfusion]
Asked On March 12, 2003 07:46 PM UTC

Hi, I am trying to set checked state of items in CheckedListbox. It works fine if it is shown by default. If it is placed on a tab page, it is not painting check marks. If the tab page is shown when setting the checked values, it works. This happens in both .NET tab control and Syncfusion TabControlExt. Is it a .NET bug? Can some one please help me. I attached the project. thanks, - Reddy

Administrator [Syncfusion]
Replied On March 13, 2003 06:26 PM UTC

Yup, I've run into this as well. In Usenet posts, MS has acknowledged this bug. The problem is essentially that any time the visibility changes on a CheckedListBox, it loses its previous selections. Naturally this happens all the time in tab controls when changing tabs. I think your best bet would be to listen to the events when the checked state of an item changes in the CheckedListBox and maintain a collection of checked items (separately from the CheckedListBox). If the CheckedListBox is hidden, it will lose its selections, but when it is shown again, you can restore the selection from your own collection. Something along those lines should work, I believe that's how we solved it in the past.

Administrator [Syncfusion]
Replied On March 18, 2003 03:36 PM UTC

I derived my own control from checked listbox and added the following code to fix the bug. ---------------------------------------- # region Workaround for CheckedListBox bug ////////////////////////////////////////////////////////////////////// // When CheckedList box becomes invisible (e.g. when the tab page // containing this control is overlapped with another tab page), // checked state of the items are getting lost. This workaround will // fix this problem ////////////////////////////////////////////////////////////////////// private bool[] isItemChecked; protected override void OnDataSourceChanged(EventArgs e) { base.OnDataSourceChanged(e); int cnt = this.Items.Count; isItemChecked = new Boolean[cnt]; for(int i = 0; i < cnt; i++) { isItemChecked[i] = GetItemChecked(i); } } protected override void OnItemCheck(ItemCheckEventArgs e) { base.OnItemCheck(e); isItemChecked[e.Index] = (e.NewValue == CheckState.Checked); } protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); if (this.Visible == true) { for(int i =0; i < this.Items.Count; i++) { //Console.WriteLine("Checkstate["+i+"] = " + this.GetItemCheckState(i) //+", new value="+isItemChecked[i]); SetItemChecked(i, isItemChecked[i]); } } } #endregion ---------------------------------------- thanks for all your help, - Reddy


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon