I'm developing a smart device project using the Compact Framework.
I have a ListView
with several checkable ListViewItem
s: the property CheckBoxes
is true. I need to check only one ListViewItem
at time, so I subscribed the ItemCheck
event:
// I need to know the last item checked
private ListViewItem lastItemChecked;
private void listView_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (lastItemChecked != null && lastItemChecked.Checked)
{
/* I need to do the following to prevent infinite recursion:
i.e. subscribe and then unsubscribe the ItemCheck event. */
listView.ItemCheck -= listView_ItemCheck;
lastItemChecked.Checked = false;
listView.ItemCheck += listView_ItemCheck;
}
lastItemChecked = listView.Items[e.Index];
}
Is there a better way to prevent the infinite recursion and thus the Stack Overflow
?