Default value selected in Combo Box after another form closes.
-
:omg::omg:Hello all, I am having 5 combo Boxes in my Form1.cs whose values are not selected. I have set SelectedIndex = -1. After this i am opening another form. Doing some operation and closing it. When the Control returns to Form1.cs all the combo Boxs are having 1st value selected. I have checked none of the events are getting fired. But by default all the combo boxes are set to SelectedIndex = 0. Any help regarding this behaviour of ComboBox Values being selected on another form closing would be highly appreciated. Thanks in Advance. --Bhoomi
-
:omg::omg:Hello all, I am having 5 combo Boxes in my Form1.cs whose values are not selected. I have set SelectedIndex = -1. After this i am opening another form. Doing some operation and closing it. When the Control returns to Form1.cs all the combo Boxs are having 1st value selected. I have checked none of the events are getting fired. But by default all the combo boxes are set to SelectedIndex = 0. Any help regarding this behaviour of ComboBox Values being selected on another form closing would be highly appreciated. Thanks in Advance. --Bhoomi
-
I am not sure but I think you will have to reset the SelectedIndex agin when the form becomes active. I think it has to do with how forms work ie STA threading model.
Hi bhoomi I think you want to select values of combos on first form on the closing of second form.... is it??? Atul
-
:omg::omg:Hello all, I am having 5 combo Boxes in my Form1.cs whose values are not selected. I have set SelectedIndex = -1. After this i am opening another form. Doing some operation and closing it. When the Control returns to Form1.cs all the combo Boxs are having 1st value selected. I have checked none of the events are getting fired. But by default all the combo boxes are set to SelectedIndex = 0. Any help regarding this behaviour of ComboBox Values being selected on another form closing would be highly appreciated. Thanks in Advance. --Bhoomi
Hi Bhoomi I think u want to change the index of combos of first form on closing of second form. If this is question then events and delegates are used int this scenario.... Atul Kumar
-
Hi Bhoomi I think u want to change the index of combos of first form on closing of second form. If this is question then events and delegates are used int this scenario.... Atul Kumar
For knowing the exact problem, i have created another application as follows : 1. MDI Form with 2 menus : Form1.cs and Form2.cs 2. Form1.cs 2 Comboboxes filled through DataTable. 3. Form2.cs Just a TextBox. Behaviour is like this : Open Form1.cs in MdiParent. ComboBoxes gets filled up. Remove the selected value manually. Open Form2. Close the Form2. Both the comboBoxes are filled up with 1st values. I am unable to undertstand why the combo boxes are filled up with initial values on its own. Any help would be highly appreciated. Regards, Bhoomi.
-
I am not sure but I think you will have to reset the SelectedIndex agin when the form becomes active. I think it has to do with how forms work ie STA threading model.
What is the behaviour of STA Threading Model. Does it fill up 1st values of the attached Datasource on Activate? Then it is a dangerours thing. If any user has set out ComboBox to be blank and opens another form then those Blanks goes away. How is the user supposed to know which all values might have changed. Is there any solution for this?? Any help would be highly appreciated. Regards, Bhoomi.
-
For knowing the exact problem, i have created another application as follows : 1. MDI Form with 2 menus : Form1.cs and Form2.cs 2. Form1.cs 2 Comboboxes filled through DataTable. 3. Form2.cs Just a TextBox. Behaviour is like this : Open Form1.cs in MdiParent. ComboBoxes gets filled up. Remove the selected value manually. Open Form2. Close the Form2. Both the comboBoxes are filled up with 1st values. I am unable to undertstand why the combo boxes are filled up with initial values on its own. Any help would be highly appreciated. Regards, Bhoomi.
Not sure why exactely but this is not the only strange behavior I see. I now that forms run on the STA threading model so a form that doesn't have the control is actually not "running". I think that when a form regains the control, it reinitilizes partly its controls, so behaviors like this are to be expected. I learned with time to be very carefull about this. There must be reading to do on this but I never took the time to do it. try to at least understand the difference between STA and MTA, it will answer many of your questions on forms. Good luck ;)