Results 1 to 5 of 5

Thread: listbox/combo box??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Unhappy

    I have a table with product and product code. The product code is a string - not integer.

    I want to populate a listbox (or combobox - dont know what is best) with the names AND codes of the products in my table so that when the user clicks on a specific productname/code I can select that specific one and display it's details.

    I know how to display the name OR the code in the listbox - how do I do both!!??

    while not rs.eof
    lstbox.additem (rs!name)
    rs.movenext
    wend

    How can I know what record the user selected!!?? I need to know this so that I can get that products specific info and display it.

    Thank you,
    T

  2. #2
    Member
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    54

    Smile Use the listindex property

    If you add the product code and product seperately to two list boxes in one loop you can use the listindex of both combo boxes is the same.

    To be sure you also use the Itemdata property of both combo boxes to store the new listindex value of the other combobox which item was added.

    Code:
    cmbProduct.Additem rs!Name
    cmbCode.Additem rs!Code
    cmbProduct.Itemdata(cmbProduct.NewIndex) = cmbCode.NewIndex
    cmbCode.Itemdata(cmbCode.NewIndex) = cmbProduct.NewIndex
    Same goes for listindex controls

    You could also consider adding a autonumber field to the table, this always creates a unique long number ID for the record to reference to. You can still use the Code field as your Primary Index.

    Hope this helps
    A mind is like a parachute, it has to open to let it work
    www.2beesoft.com for Icon Manager with over 20.000 free icons
    VB6 Ent. SP4, ASP, W2000/W98

  3. #3
    Fanatic Member faisalkm's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    752

    Smile

    Hey,

    It's better to use a listbox b'cauz it allows u to display data in multiple columns. set the listbox's column property to do it. I'm not sure this is what u want

    Faisal
    Faisal Muhammed
    Homepage:I Started making it in 1994 ...Still Under Construction
    Using

    Visual Basic 6.0 Enterprise SP5
    Embedded Visual Basic 3.0
    SQL Server 2000
    Windows 2000 Proff
    Delphi 6.0


    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile Multi Column Listbox

    May be you can use the multi Column listbox as show below, but when a use selected a item from the listbox, you need to split the name and code before you proceed to fatch the related data.

    Code:
    Option Explicit
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const LB_SETTABSTOPS = &H192
    
    Private Sub Command1_Click()
    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 1, 100)
    While not rs.eof 
        lstbox.additem rs!name & vbTab &  rs!code
        rs.movenext 
    wend 
    
    Private Sub Command2_Click()
        SplitData (List1.List(List1.ListIndex))
    End Sub
    
    Private Sub SplitData(ByVal sData As String)
    Dim i As Integer
    Dim itm(1) As Variant
    Dim iArray As Variant
    Dim idata As Variant
    
    iArray = Split(sData, vbTab, -1, vbTextCompare)
    i = 0
    For Each idata In iArray
        itm(i) = idata
        i = i + 1
    Next
    MsgBox "Selected product name is " & itm(0) & " with code = " & itm(1)
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343
    Thank you all for the help!! It will help a lot

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