\nHere is my code to delete:
\n\nvoid listBox1_MouseDoubleClick(object sender, MouseEventArgs e)\n{\n int index = this.listBox1.IndexFromPoint(e.Location);\n\n if (index != System.Windows.Forms.ListBox.NoMatches)\n {\n MessageBox.Show(index.ToString());\n\n listBox1.Items.RemoveAt(index); \n }\n}\n
\n","author":{"@type":"Person","name":"user3763373"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You can store the selected item in a variable like this
\n\nobject selected = listBox1.Items[index];\n
\n\nIs that what you're asking for?
\n","author":{"@type":"Person","name":"Thorsten Dittmar"},"upvoteCount":0}}}Reputation:
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
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