2013-04-25 49 views
1

我有一個名爲_criteria的ListView,填充了5個項目。 ListView控件的SelectionMode =「多」取消選擇Listview中的項目(windows store應用程序)

當選擇每個項目,我想通過1遞增詮釋計數,這是我可以在_crit選擇改變事件處理在這裏做的:

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

然而,對於一個的ListView項目,當它被選中時,我想增加2個計數。我該怎麼做?如果我把:

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

然後計數增加2爲我提供listViewItem4檢查提供的每隔一個選擇。另外,我想爲每個ListViewItem我取消選擇遞減計數(當listViewItem4被取消選擇時遞減2),但是在SelectionChanged事件中,它計數選擇和取消選擇,所以我不斷增加。我該怎麼辦?

回答

0

在事件中,查看e.AddedItems和e.RemovedItems以查看哪些項目已添加/從列表中刪除。如果listViewItem4在e.AddedItems中,則知道發生了什麼。

+0

謝謝。得到什麼,我一直在尋找的代碼是在這裏: 私人無效_crit(對象發件人,SelectionChangedEventArgs E) { 的foreach(在e.AddedItems ListViewItem的LV) { 計數++; if(e.AddedItems.Contains(listViewItem4)) count + = 1; } foreach(ListViewItem lv in e.RemovedItems) { count--; (e.RemovedItems.Contains(listViewItem4)) count - = 1;如果(e.RemovedItems.Contains(listViewItem4)) count - = 1; } textBox1.Text =「score is」+ count; } – BBH1023 2013-04-26 00:03:19

相關問題