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

CheckedListbox not setting checked state

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

2 Replies

AD Administrator Syncfusion Team March 13, 2003 01:26 PM

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.


AD Administrator Syncfusion Team March 18, 2003 10:36 AM

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

Loader.
Live Chat Icon For mobile
Up arrow icon