The code bellow allow to select only item in a listView. That means there is only one tick in the listView - always.
But I would like to change the code bellow that will allow to unselect too, that there will be no tick at all.
So, no tick in the listView, or only one.
This is the code I would like to change. And I can not succeed it.
bool isChecking;
bool canCheck;
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (!listView1.GetItemAt(e.X, e.Y).Checked)
{
canCheck = true;
listView1.GetItemAt(e.X, e.Y).Checked = true;
}
}
private void listView1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (!isChecking && canCheck)
{
isChecking = true;
foreach (ListViewItem item in listView1.Items)
{
item.Checked = false;
}
listView1.Items[e.Index].Checked = true;
e.NewValue = CheckState.Checked;
canCheck = false;
isChecking = false;
}
else
{
if (isChecking)
{
e.NewValue = CheckState.Unchecked;
}
else
{
e.NewValue = e.CurrentValue;
//Now I have a method here, when the new tick is checked!
}
}
}