Results 1 to 6 of 6

Thread: Combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93

    Combobox

    Here's what I'm trying to do:

    I want the user to be able to edit data using a combobox. When the form is filled with data I want the combo box to be filled with the selection based on a query & have the combo be filled with the value from the table. If the user needs to edit this data then on selecting the combo box dropdown, all of the items will be there to choose from, the user selects the new value and saves that new value to the database.

    Example:

    On form load:

    Combobox value shown: Uptown
    Combobox filled with :
    Downtown
    Midtown
    Uptown

    I need tobe able to have the user then select another value to save. I have the combobox loaded with the values but when it pops the value Downtown is shown because sorts to the top. How do I make the Uptown value show in the combobox but yet still have all values show when the combo is dropped down so the user can select another?

    This is what I have so far to fill the combo:

    Dim dsShowrooms As WarehouseSet
    dsShowrooms = Warehouse.FillShowroomCombo
    ComboBox1.DataSource = dsShowrooms.Tables(0)
    ComboBox1.DisplayMember = "WarehouseName"

    Public Function FillShowroomCombo() As WarehouseSet

    Dim sql As String

    sql = "SELECT WarehouseCode, WarehouseName "
    sql &= "FROM Warehouses "
    sql &= "WHERE WarehouseCode <> '99' "
    sql &= "ORDER BY WarehouseTypeID, WarehouseName"

    Return CType(Me.GetEntitySet(sql, GetType(WarehouseSet)), WarehouseSet)

    End Function

    I hope I have explained this ......... if I haven't I'd be glad to try again.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Two ways (assuming this is your actual data):

    1. set the combobox.selectedindex to 2. This will display the third value in the combobox.

    2. In your SQL, use ORDER BY 'WarehouseName' ASC. This will sort your results in aplhabetical order (ASC is the default, so you can omit it if you want. DESC would list in reverse alphabetical order).

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    slavelinus,

    Thanks for responding but that's not what I'm trying to do.

    If the value in the database for the selected row is Uptown then I do want that to show in the combobox. What I then need to happen is if the location needs to be edited, the user can then select the dropdown button on the combobox and when the combo drops all of the values will be in the box and the user can then select the new data.

    Corinne

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    I guess I'm not clear on what you want. Do you want the user to be able to edit the values in the combobox? If you've populated the combobox with the warehousenames, they should still be there. If you mean something else, I don't get what you mean, sorry.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    I'm sorry, I'm having a hard time explaining what I need.

    I need the user to be able to edit the valuse in the combobox. I have populated the combobox witht he values and they are still there. What I'm having a problem with is when the combobox is filled the nature of the box is to show the first item that is loaded. This item isn;t necessarily the value that belongs there based on the results from the query.

    Let's try this:

    STEP 1: Form loads and combobox1 is filled with Customer Name
    Customer name is selected by user and on selectedvalue changed several controls are filled with data cooresponding to the customer that was selected in combobox1. One of these controls is another combobox (combobox2) that contains location information.
    STEP2: At this point I need combobox2 to show the correct value (Let's say UpTown) because UpTown is the location value associated with the customer selected in combobox1.
    STEP3: When the user selects an edit button, combobox2 becomes enabled and when the user clicks the dropdown arrow, combobox2 drops and the user can see all of the values in the dropdown. User selects another value, let's say MidTown and clicks the save button.

    Heres my issue. On STEP2 combobox2 shows the first item in the list (DownTown) but I need it to show the value that cooresponds to the customer name (UpTown).

    I posted the code I have so far to fill the combobox. Can anyone please tell me what I'm missing.

    Hopefully this helps you .... thanks for trying to help me out.

    Corinne

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    If the issue is just that you want it to show Uptown, you could just set the text for combobox2 to "Uptown". (I'm assuming you get Uptown from the code behind combobox1). This wouldn't re-order the items when the user drops the box down, but would show the value you want.
    Alternatively, you could loop through the values in combobox2 looking for a match with Uptown, getting the index of that item, and either setting the selectedindex of combobox2 to that index (not changing the order in the dropdown), or swap the indexes of the first item and the item with Uptown (which would change the order in the dropdown).
    That's my untested 2 cents, anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width