C# Winform - Updating Combobox hangs application.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somacore
    New Member
    • Apr 2008
    • 24

    C# Winform - Updating Combobox hangs application.

    I have a winform with a combobox. This combobox's text is set to a value from the database (in this case, a number). In my code I take the number and convert it to the proper text, returning the value as the selecteditem for the combobox. This part works.

    However, if I try to UPDATE the value in the combobox at runtime, I am able to select the new value, but after that I cannot do anything. I am unable to select any other element on my form (textboxes, comboboxes, etc). The program basically hangs and I have to exit. The new value in the problem combobox stays highlighted though, and kind of "sticks" there.

    Any ideas are welcome.

    Code is below.

    Code:
    int PATesting = Convert.ToInt32(comboBox73.Text);
                    string TestStatus = " ";
                    switch (PATesting)
                    {
                        case 0:
                            TestStatus = "Assigned";
                            break;
                        case 1:
                            TestStatus = "Working";
                            break;
                        case 2:
                            TestStatus = "Code Submitted";
                            break;
                        case 3:
                            TestStatus = "In Testing";
                            break;
                        case 4:
                            TestStatus = "Passed";
                            break;
                        case 5:
                            TestStatus = "Failed";
                            break;
                        case 6:
                            TestStatus = "Hold";
                            break;
                        case 7:
                            TestStatus = "In Production";
                            break;
                    }
                    this.comboBox73.SelectedItem = TestStatus;
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    My guess is you are doing something in the value changed (index/value/whatever changed) event for the combobox and in THAT event, also changing the value. Making a cycle.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Have you tried using
      [code=cpp] this.comboBox73 .SelectedText = TestStatus;[/CODE]?

      -Frinny

      Comment

      • somacore
        New Member
        • Apr 2008
        • 24

        #4
        Originally posted by Frinavale
        Have you tried using
        [code=cpp] this.comboBox73 .SelectedText = TestStatus;[/CODE]?

        -Frinny

        I have not tried that, but I will.


        Originally posted by Plater
        My guess is you are doing something in the value changed (index/value/whatever changed) event for the combobox and in THAT event, also changing the value. Making a cycle.
        Actually, I don't have any events fire for that combobox. I do, for some other comboboxes on the same form, but not that one.

        Comment

        • somacore
          New Member
          • Apr 2008
          • 24

          #5
          Originally posted by somacore
          I have not tried that, but I will.
          SelectedText yields the same result.

          When it freezes up like that, I can still access the combobox menu and pick whatever i want, but i can't tab or click out of it. The only other menus I can access are the file and help (the only ones I have), and at that point I have to click file > exit to close the app.

          Comment

          • somacore
            New Member
            • Apr 2008
            • 24

            #6
            Bump? I can't find anything like this on Google.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              I don't think I understand how you populate the combobox.
              You said it pulls from a database (Datasource property?) and that it sets the text to a number. Then you change these numbers to the text you actually want?
              That seems sorta silly?
              Seems to me like you should populate the combobox with the actual texts you want and then SELECT the index of the one from the number (so if the database returns a 2, you would have index 2 selected from the combobox, which should be your correct text displayed)

              Comment

              • somacore
                New Member
                • Apr 2008
                • 24

                #8
                Originally posted by Plater
                That seems sorta silly?
                Seems to me like you should populate the combobox with the actual texts you want and then SELECT the index of the one from the number (so if the database returns a 2, you would have index 2 selected from the combobox, which should be your correct text displayed)
                It does, but I'm not really seeing a way to implement what you're describing. My combobox has all my texts that I want - they're hardcoded in there. I don't see a way to associate each item with an index?

                I'll look into this. Thanks for the reply.

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  int idx =ValueFromDataB ase();
                  myCombobox.Sele ctedIndex=idx;

                  Comment

                  • pootle
                    New Member
                    • Apr 2008
                    • 68

                    #10
                    Originally posted by somacore
                    SelectedText yields the same result.

                    When it freezes up like that, I can still access the combobox menu and pick whatever i want, but i can't tab or click out of it. The only other menus I can access are the file and help (the only ones I have), and at that point I have to click file > exit to close the app.
                    You surely see something in the debugger when this blocking behaviour occurs. What is in the call stack of each thread?

                    Comment

                    Working...