1
votes

I have a ListView named _criteria, populated with 5 items. ListView SelectionMode="Multiple"

When each item is selected, I want to increment the int count by 1, which I can do here in the _crit Selection Changed event handler:

    private void _crit(object sender, SelectionChangedEventArgs e)
    {
        count++;
        textBox1.Text = "this is "+count;
    }

However, for one of the ListView items, when it's selected, I want to increment count by 2. How do I do this? If I put:

        if (_criteria.SelectedItem == listViewItem4)
            count += 2;

then count is incremented by 2 for every other selection I make provided listViewItem4 is checked. Also, I want to decrement count by 1 for every ListViewItem I deselect (and decrement by 2 when listViewItem4 is deselected) but in the SelectionChanged event, it counts both selection and deselection, so I keep getting increments. What do I do?

1

1 Answers

0
votes

In the event, look at e.AddedItems and e.RemovedItems to see which items have been added/removed from the list. If listViewItem4 is in e.AddedItems, you know what has happened.