HELP with ComboBoxes


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: HELP with ComboBoxes

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    HELP with ComboBoxes

    [Originally posted by lokiloki]

    I am reading a small database into a combobox.
    It has two fields and I have sent the first field values to the 1st Combobox.
    But I need to send the second field values to a second combobox that has the correct row values that corespond to the first field.

    I tried this˙
    Combo3.AddItem (rs!clientname)
    Combo1.AddItem (rs!systemname)

    but the values were not indexed correctly.
    Got the field values as seperate items.
    I need them to show like this:


    Database
    Field 1˙ ˙ ˙ ˙  Field2
    Item1˙ ˙ ˙ ˙ ˙  Item2
    Item3˙ ˙ ˙ ˙ ˙  Item4

    ˙ 
    Combo1:˙  Item1
    Combo2:˙  Item2

    Select next item in Combo1 (item3) and I need item 4 to show up in Combo2

    Combo1:˙ ˙ Item3
    Combo2:˙ ˙ Item4

    Thanks in advance !!˙ 

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:HELP with ComboBoxes

    [Originally posted by ledis]

    Assume the associated values in the 2 lists are putted in the same row.

    Private Sub Combo1_Click()
    combo2.Text = combo2.List(combo1.ListIndex)
    End Sub

    : & )

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:HELP with ComboBoxes

    [Originally posted by ledis]

    *************************************
    Combo3.AddItem (rs!clientname)
    Combo1.AddItem (rs!systemname)

    but the values were not indexed correctly.
    ***************************************

    The sorted property in combo1 and combo2 should be false if you want them just appended on.
    : & )

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:HELP with ComboBoxes

    [Originally posted by lokiloki]

    I assume I just add this to the Combo1.additem˙

    Thanks Much !!

  5. #5
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:HELP with ComboBoxes

    [Originally posted by lokiloki]

    Didn't work here's the actual code I have for this:

    Private Sub Command8_Click()
    Dim x As Integer
    Dim y As Integer
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.ConnectionString = App.Path & "\clients.mdb"
    cn.Open

    rs.Source = "select * from clients"
    rs.Open , cn, adOpenKeyset, adLockOptimistic

    Do Until rs.EOF
    ˙ x = Len(Left(rs!clientname, 38))
    ˙ x = 38 - x
    ˙ y = Len(Left(rs!SystemName, 20))
    ˙ y = 22 - y
    ˙ ˙ Combo3.AddItem (rs!clientname) ' THIS WORKS
    ˙ SendMessage Combo3.hwnd, CB_SHOWDROPDOWN, True,0
    ˙
    ˙ rs.MoveNext
    Loop

    rs.Close
    cn.Close
    Set rs = Nothing
    Set cn = Nothing

    Combo1.Text = Combo1.List(Combo3.ListIndex) THIS ONLY DROPS DOWN A EMPTY COMBO BOX

    'Combo1.AddItem Combo1.List(Combo3.ListIndex)

    SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0

    Combo2 depends on what the user's choice is in Combo1.

    The field values are on the same row in the database and sorted property is set to false.

  6. #6
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:HELP with ComboBoxes

    [Originally posted by ledis]

    Why i didn't see Combo1.additem???
    In your program there is no code for combo1 to add item.
    Surely it will be empty!!!!!.
    : & )


    Do Until rs.EOF
    ˙ x = Len(Left(rs!clientname, 38))
    ˙ x = 38 - x
    ˙ y = Len(Left(rs!SystemName, 20))
    ˙ y = 22 - y
    ˙ ˙ Combo3.AddItem (rs!clientname) ' THIS WORKS
    *** 'SHOULD IT BE HERE?
    *** 'Combo1.additem (rs!SystemName)

    SendMessage Combo3.hwnd, CB_SHOWDROPDOWN, True,0
    ˙
    ˙ rs.MoveNext
    Loop


  7. #7
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:HELP with ComboBoxes

    [Originally posted by lokiloki]

    Sorry, I didn't paste it all, the conbo1 is at the end of the sub.


    Do Until rs.EOF
    ˙ x = Len(Left(rs!clientname, 38))
    ˙ x = 38 - x
    ˙ y = Len(Left(rs!SystemName, 20))
    ˙ y = 22 - y
    ˙ 'List1.AddItem rs!clientname & Space(x) & Space(2) & Left(rs!SystemName, 20) & Space(y) & rs!DialupPhone
    ˙ Combo3.AddItem (rs!clientname)
    ˙ SendMessage Combo3.hwnd, CB_SHOWDROPDOWN, True, 0
    ˙
    ˙ rs.MoveNext
    Loop

    rs.Close
    cn.Close
    Set rs = Nothing
    Set cn = Nothing

    Combo1.AddItem Combo1.List(Combo3.ListIndex)

    SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0

  8. #8
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:Re:HELP with ComboBoxes

    [Originally posted by ada]

    Your code really make me blurred.

    1) Does Combo1 and Combo3 has same number of items?
    Because you add combo3 with a loop but combo1 with only 1 line.

    2)Combo1.AddItem Combo1.List(Combo3.ListIndex)
    The thing the code it does: Select an item form COMBO1 that has the same index number with the one selected in COMBO3 and add it again to COMBO1.
    Then every time you run this code, it will only add item from itself or NOTHING.

    Should it be Combo1.Additem Combo3.list(Combo3.listIndex).

    3)One advice: Make clear of what each line of code will do for you.

    : & )

  9. #9
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:Re:Re:HELP with ComboBoxes

    [Originally posted by lokiloki]

    Database is:
    ˙ ˙ ˙ ˙ ˙ ˙ Column1(field name:clientname)˙ ˙ ˙ Column2(field name: systemname)
    Row1˙ ˙ ˙ ˙ ˙ Bingo˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ Pav˙ ˙
    Row2˙ ˙ ˙ ˙ ˙ EverettB˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ POS1

    User selects clientname from Combo3, ie Bingo, and the correct coresponding systemname is in Combo1, ie Pav˙

    Combo3.AddItem (rs!clientname) 'Adds first field values (Field name: clientname˙ (row 1, column 1) from MDB to Combo3

    Combo1.AddItem Combo3.List(Combo3.ListIndex) ' Want to add 2nd field values (Field name: SystemName (row 1, colunm 2) from MDB


    ˙ ˙ ˙ ˙ ˙ ˙ ˙

  10. #10
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:Re:Re:Re:HELP with ComboBoxes

    [Originally posted by ada]


    Combo3.AddItem (rs!clientname) 'Adds first field values (Field name: clientname˙ (row 1, column 1) from MDB to Combo3

    Combo1.AddItem (rs!systemname) 'Adds second field values (Field name: systemname (row 1, column 2) from MDB to Combo1


  11. #11
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:Re:Re:Re:Re:HELP with ComboBoxes

    [Originally posted by lokiloki]

    I scrapped that way and used a DATA control bound to two text boxes. Worked !
    I want to thank you for all your help, you showed me things I can use in the future !

    THX !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center