如何处理 VB.NET 中 ListBox 的 SelectedIndex 和双击事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14522834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Handle SelectedIndex and Double Click event for ListBox in VB.NET?
提问by Hemant Kumar
I have a functionality regarding the double clickof ListBox which already has SelectedIndexChangedevent.The same events in vb6 works fine,but when it comes to single click the SelectedIndexChanged Event is firing always when I click for Double Click also.
我有一个关于双击ListBox的功能,它已经有SelectedIndexChanged事件。vb6 中的相同事件工作正常,但是当涉及到单击时,SelectedIndexChanged 事件总是在我单击双击时触发。
I have tried to use timer and prevent the SelectedIndexChanged event,but no use always firing the SelectedIndexChanged event.
我尝试使用计时器并阻止 SelectedIndexChanged 事件,但始终触发 SelectedIndexChanged 事件没有用。
The event sequence in Vb is different when compared to VB.NET.
与 VB.NET 相比,Vb 中的事件序列是不同的。
回答by spajce
The ListBox have two Event to Handle the Double Click
ListBox 有两个事件来处理双击
- DoubleClick Event
- MouseDoubleClick Event
- DoubleClick 事件
- 鼠标双击事件
msdn: Control.DoubleClick Event
Example for DoubleClick Event with items: C# Listbox Item Double Click Event
带有项目的 DoubleClick 事件示例:C# 列表框项目双击事件
回答by chara
You can't have both MouseDoubleClick and SelectedIndexChanged. When SelectedIndexChanged is used it supersedes MouseDoubleClick. Try using one or the other.
您不能同时拥有 MouseDoubleClick 和 SelectedIndexChanged。当使用 SelectedIndexChanged 时,它会取代 MouseDoubleClick。尝试使用其中一种。
To be more exact, when the control is empty then MouseDoubleClick is fired but as soon as an item is added then SelectedIndexChanged fires and not MouseDoubleClick.
更准确地说,当控件为空时,MouseDoubleClick 会被触发,但一旦添加了一个项目,SelectedIndexChanged 就会触发,而不是 MouseDoubleClick。
Hope this helps.
希望这可以帮助。

