Reputation: 17016
Suppose I need to change the status of an item from active = true to active = false and vise versa and at the same time persist my change in the database table.
I tested ItemChecked event like the following:
private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
ListViewItem item = (ListViewItem)sender;
if (item != null)
{
Book b = (Book) item.Tag;
b.MakeActive(item.Checked);
}
}
I failed.
Can anyone help me?
Upvotes: 0
Views: 14582
Reputation: 16065
in this case object sender
is ListView
and not ListViewItem
your code should be this
private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
ListViewItem item = e.Item as ListViewItem;
if (item != null)
{
Book b = (Book) item.Tag;
b.MakeActive(item.Checked);
}
}
Upvotes: 4