C# Listbox Item Double Click Event

Ozzy picture Ozzy · Dec 15, 2010 · Viewed 132.9k times · Source

I have a list box with some items. Is there anyway I can attach a double click event to each item?

Item 1
Item 2
Item 3

If i was to double click Item 2, a Messagebox saying "Item 2" would pop up

How would i do this?

Answer

Dark Knight picture Dark Knight · Dec 15, 2010
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
         int index = this.listBox1.IndexFromPoint(e.Location);
         if (index != System.Windows.Forms.ListBox.NoMatches)
            {
              MessageBox.Show(index.ToString());
            }
     }

This should work...check