I have 4 items in a ListBox and each item does a specific thing when it gets clicked on.
But I also want the double click event to do the same thing as the click event.<
These solutions only work if the code to be executed is available to the class (Class A), which may not be the case if you are building a library. If the control(s) which should execute the same code are in a class which is going to be instantiated in another class (Class B), and the instatiating class is where the code to be executed will be defined, then you can do this:
Class A
Public Event ListDoubleClickOrClick()
Private Sub HandleListDoubleClickOrClick(sender As Object, e As System.EventArgs) Handles listObject.DoubleClick, listObject.Click
RaiseEvent ListDoubleClickOrClick()
End Sub
Class B
private sub theCodeToBeExecuted()
end sub
dim objClassA as A
AddHandler objClassA.ListDoubleClickOrClick, AddressOf theCodeToBeExecuted
Try Following Code!
Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click
ListBox1_DoubleClick(sender, e)
End Sub
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
MsgBox(ListBox1.Items.Count)
End Sub
Same routine can handle both events. Code:
Private Sub ListBox1_AllClicks(
ByVal sender As Object, ByVal e As System.EventArgs)
Handles ListBox1.Click, ListBox1.DoubleClick
You can set this up in the listbox properties: view events and use the dropdown next to DoubleClick to choose an existing routine.