Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Default value selected in Combo Box after another form closes.

Default value selected in Combo Box after another form closes.

Scheduled Pinned Locked Moved C#
help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhoomi kakaiya
    wrote on last edited by
    #1

    :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

    J A 2 Replies Last reply
    0
    • B bhoomi kakaiya

      :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

      J Offline
      J Offline
      Johnny 0
      wrote on last edited by
      #2

      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.

      A B 2 Replies Last reply
      0
      • J Johnny 0

        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.

        A Offline
        A Offline
        atulonweb hotmail com
        wrote on last edited by
        #3

        Hi bhoomi I think you want to select values of combos on first form on the closing of second form.... is it??? Atul

        1 Reply Last reply
        0
        • B bhoomi kakaiya

          :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

          A Offline
          A Offline
          atulonweb hotmail com
          wrote on last edited by
          #4

          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

          B 1 Reply Last reply
          0
          • A atulonweb hotmail com

            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

            B Offline
            B Offline
            bhoomi kakaiya
            wrote on last edited by
            #5

            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.

            J 1 Reply Last reply
            0
            • J Johnny 0

              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.

              B Offline
              B Offline
              bhoomi kakaiya
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • B bhoomi kakaiya

                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.

                J Offline
                J Offline
                Johnny 0
                wrote on last edited by
                #7

                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 ;)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups