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
Stoitcho Goutsev \(100\) [C# MVP] - 26 Oct 2004 14:56 GMT
Hi Robke,
Isn't it easier if you do something like the following
while(this.checkedListBox1.CheckedIndices.Count > 0)
{
this.checkedListBox1.Items.RemoveAt(checkedListBox1.CheckedIndices[0]);
}

Signature
HTH
Stoitcho Goutsev (100) [C# MVP]
> Hi,
>
[quoted text clipped - 27 lines]
> Regards,
> Robke