Additem (multiple) from selected in listbox into combobox

Posted on 2006-05-24
Last Modified: 2008-03-03

I have a listbox that when you select an item it adds it into a combo box.  This is all working fine but I wish to add the value from listbox column 1 into combo box column 1 and then the value from listbox column 2 into combobox column 2.  For some reason when I try to add the second parameter to specify the column I get an error.  Below is the current code that I am using

Private Sub lbxProduct_Change()

Dim iCount, i As Integer
Dim strProd, strProd2 As String

    iCount = 0


    For i = 0 To lbxProduct.ListCount - 1
        If lbxProduct.Selected(i) Then
            iCount = iCount + 1
            strProd = lbxProduct.List(i, 0)
            strProd2 = lbxProduct.List(i, 1)
            With cboPrimaryProduct
                .AddItem (strProd, 0)                                     'This is where the error is
                .AddItem (strProd2, 1)
            End With
        End If
    Next i
    lblTest.Caption = iCount

End Sub
Question by:wobbled
    LVL 76

    Accepted Solution

    Additem adds a row, so add the first column data, then add the second column data into the row.

                With cboPrimaryProduct
                    .AddItem strProd
                    .List(.ListCount - 1, 1) = strProd2
                End With
    LVL 17

    Author Comment

    Brilliant, Thanks for that

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
    If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
    This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
    This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now