Reputation:
I have a program and i want to remove the data when i click double to any data. How can i do that? This is the part of my code:
this.listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_MouseDoubleClick);
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.Remove(listBox1.IndexFromPoint(e.Location));
}
}
Upvotes: 1
Views: 35
Reputation: 17550
The Remove()
method needs the object which you want to remove as a parameter. To use an index use the RemoveAt()
method:
listBox1.Items.RemoveAt(index);
Upvotes: 3