user3763373
user3763373

Reputation:

how can i get the value of index in listbox?

I am writing a c# windows form application program on vb. I have a listbox and when I double-click on any data it is removed but before delete it I want to keep the data in a string or integer. How can i do that?
Here is my code to delete:

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());

        listBox1.Items.RemoveAt(index);              
    }
}

Upvotes: 0

Views: 1029

Answers (1)

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56727

You can store the selected item in a variable like this

object selected = listBox1.Items[index];

Is that what you're asking for?

Upvotes: 0

Related Questions