Reputation: 345
Is it normal for ListBox to fire the DoubleClick event handler method twice when an item is selected? For several days I have attempted to locate what could be causing this and can't seem to isolate any issue that should cause for the Listbox to fire the event handler method twice and am beginning to believe that this could just be the normal response. Does anyone have any experience with this issue or offer any insight?
...
listBox1.Items.Clear();
listBox1.DoubleClick += filteredAlbum_DoubleClick;
foreach (XmlNode node in replyNode.ChildNodes)
{
listBox1.Items.Add(node.ChildNodes[0].Value); }
}
listBox1.SelectedIndex = 0;
...
private void filteredAlbum_DoubleClick(object sender, EventArgs e)
{
var selectedItem = listBox1.SelectedItem.ToString();
MessageBox.Show(ActiveFilter + " = " + selectedItem);
}
Thanks, Bill
Upvotes: 0
Views: 1143
Reputation: 78180
I'd guess you're adding your listBox1.DoubleClick
handler twice.
Each event handler will be called once, even if that is actually the same handler added several times. Clearing a listbox does not clear previously bound handlers.
Upvotes: 2