Как избежать нежелательного selectedindexchanged в combobox
Hello In form1, i added comboBox1 that has 3 items (10, 20 and 30) and a textBox1 My goal is to copy the selected item from comboBox to the textBox1 by using SelectedIndexChanged (usi.ng the mouse), the program works fine However, when the program start the SelectedIndexChanged event is called from somewhere else. I tried to avoid this undesirable call by adding a variable Flag and make it equal zero in formload and in SelectedIndexChanged event I added if else statement hopping skip that call ..I could not
Что я уже пробовал:
private void comboSelctIndChanged(object sender, EventArgs e) { //in formload i added variable Flag=0 and added all items to combobox if (Flag == 0) { MessageBox.Show("Flag=", Flag.ToString()); Flag = 1; MessageBox.Show("Now Flag=", Flag.ToString()); } else { MessageBox.Show("Flag=", Flag.ToString()); ComboBox senderComboBox = (ComboBox)sender; MessageBox.Show("sender ", senderComboBox.Text); textBox1.Text = senderComboBox.Text; } }