As it says in tilte:
- there is a ListBox
- when I select a value in
- 1st SelectedValueChanged event contains value I clicked on
- and time to time there is 2nd SelectedValueChanged event contains 1st value from the list
I catched it adding those piece of code:
This is what my designer contains:
this.listBox1.SelectedValueChanged +=
new System.EventHandler(this.listBox1_SelectedValueChanged);
This is what my class contains :
public class myControl : UserControl
{
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
StackTrace st = new StackTrace(true);
} /// I put breakpoint that line to look at st
}
I cannot see where 2nd event is fired. In the stack there is plenty of system code and nothing very revelant from my own code. But I can past it here on demand.
The only thing I'm not really mastering is the UserControl
context. Maybe something to do around that.
With that, do you have an idea about why I got twice call when I click once ?
edit after King King's question:
scenario is:
affecting
listBox1.DataSource
callsSelectedValueChanged
- in
listBox1_SelectedValueChanged
sender:{SelectedItem = "1st value"} object {System.Windows.Forms.ListBox}
- in
clicking to 3rd value in
listBox1
calls twiceSelectedValueChanged
- in
listBox1_SelectedValueChanged
sender:{SelectedItem = "3rd value"} object {System.Windows.Forms.ListBox}
- in
listBox1_SelectedValueChanged
sender:{SelectedItem = "1st value"} object {System.Windows.Forms.ListBox}
- in
after that only 1st value is selected