Search code examples
c#eventslistboxlistboxitemdouble-click

C# Listbox Item Double Click Event


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?


Solution

  • 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