I'm going to respond to your question on a little "broader" level (once an educator, always an educator ?) than just the
how of you get a specific DoubleClick EventHandler "wired-up" to a specific ListBox.
First, what are your goals here:
1. what happens if the user only single-clicks on an entry in the ListBox, but that single-click changes the current SelectedIndex Property of that ListBox: does that potential change in selection by single-click "mean" anything in the context of your solution ?
Please note that ... sometimes .... depending on external variables, system settings, mouse-type, how fast you click, how worn-down your mouse-buttons are, etc., it's possible to "have trouble" getting a double-click Event.
Try this WinForm experiment: put a ListBox (here called 'listBox1), with the same three Items in it (Dog Cat Fish) you are using now, and add a large-sizedTextBox with 'Multi-Line set to 'true, and set to show a vertical scrollbar, named 'tbEventReport.
Add this code to the Form that contains the 'listBox1 ListBox, and the 'tbEventReport TextBox:
private int eventId;
private void ReportEvent(string eventName)
{
tbEventReport.Text +=
"Event ID ="
+ eventId
+ " : "
+ eventName
+ " : "
+ "Selected Index = "
+ listBox1.SelectedIndex
+ Environment.NewLine
+ "-----------------------------------------------------------------------------------------------------"
+Environment.NewLine;
eventId++;
}
private void listBox1_MouseClick(object sender, MouseEventArgs e)
{
ReportEvent("MouseClick");
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
ReportEvent("MouseDoubleClick");
}
private void listBox1_Click(object sender, EventArgs e)
{
ReportEvent("Click");
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
ReportEvent("DoubleClick");
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ReportEvent("SelectedIndexChanged");
}
}
Do the right thing at design-time to "hook-up" those EventHandlers defined above to 'listBox1.
Then run the app, and experiment with clicking and double-clicking in a variety of ways: notice how clicking on the same item that's already selected still fires the SelectedIndexChanged EventHandler.
Getting "grounded" in the sequence and behavior of typical Mouse action generated Events will, I believe, equip you with a "mental toolkit" you can use to design many types of solution strategies in the future.