AD
Administrator
Syncfusion Team
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.
AD
Administrator
Syncfusion Team
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