I've been using this property of a ListView
:
SelectedIndexChanged
However, it gets triggered also when item is unselected.
What is the best event if I only want event to be triggered when an item is actually selected, and to be called only once? Not twice in a row like ItemActivate
.
You can use the SelectedItems.Count
property in your ListView
, return whenever its 0
, or handle the event if its greater than 0
, so all you need is an if statement in your event handler such as
if(yourListView.SelectedItems.Count == 0)
return;
//Do your thing
Or:
if(yourListView.SelectedItems.Count > 0){
//Do your thing
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.