如何在双击列表框中的项目时运行子项

时间:2015-08-20 18:45:39

标签: vb.net

我有一个列表框,随着程序的使用逐渐填充订单。但是,我想在双击列表框中的任何项目时打开一个单独的表单。

handles lstbox.selectedindexchanged

不是我正在寻找的,也不是:

handles lstbox.doubleclick

因为只要双击控件上的任何索引,它们就会分别运行。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

WinForms ListBox控件上没有内置任何内容,因此请使用MouseDoubleClick事件来模拟它:

Private Sub ListBox1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseDoubleClick
  Dim index As Integer = ListBox1.IndexFromPoint(e.Location)
  If index > -1 AndAlso index = ListBox1.SelectedIndex Then
    MessageBox.Show(ListBox1.SelectedItem.ToString)
  End If
End Sub
相关问题