开发者

Get most recently selected item (WinForms)

开发者 https://www.devze.com 2022-12-22 14:57 出处:网络
Scenario: Windows Form Listbox SelectionMode = MultiSimple Items 1 and 5 are selected already User selects item 3 by clicking on it or by pressing the spacebar after it has focus

Scenario:

  • Windows Form
  • Listbox
  • SelectionMode = MultiSimple
  • Items 1 and 5 are selected already
  • User selects item 3 by clicking on it or by pressing the spacebar after it has focus

Q: How do I get its index or value on SelectionChanged? I.e., how do I know which item was just selected (or de-selected)? FYI, SelectedItem will return item 1 (i.e., the item at index 开发者_JAVA技巧0 in the SelectedItems collection).


You want to use SelectedItems, it will tell you all of the items that are selected.

In terms of knowing with item was just selected, you might have to remember what the old SelectedItems are, and compare to the new SelectedItems.

You can also check the EventArgs of the SelectionChanged event, however, I don't think it gives you that information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号