C# Windows Form - Comboboxes and SelectedItems

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

    C# Windows Form - Comboboxes and SelectedItems

    I'm just learning C# for this huge project at work, so bear with me. This application takes ticket numbers from the user and displays the ticket information in the form. Simple enough. I'm having an issue though with the comboboxes.

    Since I want users to be able to update the tickets (and this works, so far except on these stupid boxes), the comboboxes should display the data from the specific ticket as the selected item, but ALSO have a dropdown list of all the possible values for that combobox. For this example we'll use the "Site Name" combobox, which is combobox55 on my form.

    The first part, displaying the data from the ticket, works fine. The second part, displaying a list of all possible data, does not.

    In the "Combobox Tasks" window in VS2005 I have as the Datasource the "Sitename" datasource, and the display and value member boxes both are set to "site." (which I have configured and tested, selecting "Preview data" shows all the site names.) The Selected Item box has the table row that corresponds to the Site Name coming from the ticket database.

    However when I type in the ticket number, the box is populated only with the Site name for that ticket, and nothing else.

    I have tried the "Add query" dialog, but all it does is add a toolstrip to the top of my window? I'm not sure how that works.

    Thanks,
    Mike
  • rjvrnjn
    New Member
    • Apr 2007
    • 26

    #2
    Originally posted by somacore
    However when I type in the ticket number, the box is populated only with the Site name for that ticket, and nothing else.
    Are you re-populating the data in the combo-boxes based on user input in the ticket number? If yes, how are you doing that?

    Comment

    • somacore
      New Member
      • Apr 2008
      • 24

      #3
      Originally posted by rjvrnjn
      Are you re-populating the data in the combo-boxes based on user input in the ticket number? If yes, how are you doing that?

      I'm not re-populating really, just populating. When the form loads up, the fields are blank, but then when the user enters a ticket and clicks the button, the DB gets called and fills up the fields.

      If the user searches for a second ticket, the fields all flush (apparently through some built in mechanism, because I'm not doing that) and they display the ticket.

      Relevant code to fill the form in question:

      this.hD__Troubl e_TicketTableAd apter.FillBy_Ca seID(this.dataS et2.HD__Trouble _Ticket, CaseID);

      Where CaseID is the trouble ticket number.

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        It sounds like you want the drop down list to include all of the Site Names possible and the site name that currently exists for the ticket number. You may want to use a proc (datasource query) to bring back the possible site names and then just add the site name that currently exist (a separate query would give you the data for a ticket number) for that ticketNumber to the dropdownlist manually.

        Here is an example of how to add items manually (in the code behind) to a combobox.


        Nathan

        Comment

        • rjvrnjn
          New Member
          • Apr 2007
          • 26

          #5
          If I get your issue correctly, I say I would have taken a different approach. If you want to populate the site drop down only after the user has entered a trouble ticket, then get all the possible values into the site combo and set the selectedText or SelectedValue to the current ticket's site value. But if you want to build up the site combo list as the user keeps on entering the ticket number then the method suggested above is the way to go.

          Comment

          Working...