Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView.ItemCheck versus ListView.ItemChecked in .NET

What is the difference between the ListView.ItemCheck and ListView.ItemChecked events in .NET?

like image 377
sourcenouveau Avatar asked May 26 '09 21:05

sourcenouveau


1 Answers

The ItemCheck event is triggered when the checked state of an item is about to change, allowing you to examine the old and new value, and to cancel the change if you wish (by assigning the NewValue property of the eventargs parameter). ItemChecked is triggered after the check (or uncheck) is completed.

Code sample:

private void ListView_ItemCheck(object sender, ItemCheckEventArgs e)
{
    // the checked state of an item is about to change
    if (e.NewValue == CheckState.Checked)
    {
        // perform some check if this is allowed, and if not...
        e.NewValue = e.CurrentValue;
    }
}

private void ListView_ItemChecked(object sender, ItemCheckedEventArgs e)
{
    // the checked state of an item has changed
}
like image 149
Fredrik Mörk Avatar answered Oct 08 '22 05:10

Fredrik Mörk