14

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

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243

1 Answers1

28

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
}
bluish
  • 26,356
  • 27
  • 122
  • 180
Fredrik Mörk
  • 155,851
  • 29
  • 291
  • 343