views:

1390

answers:

1

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?

A: 

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);
    }
}
Stan R.