R
Robke
Hi,
I've had problems deleting checked items from CheckedListBox. Tried searching
the web for solution and then a nice idea came into my mind. Recursion!
So I wrote a simple function:
private void deleteItems(int index)
{
if (checkedListBox1.Items.Count <= index)
return;
else
{
if (checkedListBox1.GetItemCheckState(index) == CheckState.Checked)
{
checkedListBox1.Items.RemoveAt(index);
deleteItems(index);
}
else deleteItems(index+1);
}
return;
}
private void button1_Click(object sender, System.EventArgs e)
{
deleteItems(0);
}
Regards,
Robke
I've had problems deleting checked items from CheckedListBox. Tried searching
the web for solution and then a nice idea came into my mind. Recursion!
So I wrote a simple function:
private void deleteItems(int index)
{
if (checkedListBox1.Items.Count <= index)
return;
else
{
if (checkedListBox1.GetItemCheckState(index) == CheckState.Checked)
{
checkedListBox1.Items.RemoveAt(index);
deleteItems(index);
}
else deleteItems(index+1);
}
return;
}
private void button1_Click(object sender, System.EventArgs e)
{
deleteItems(0);
}
Regards,
Robke