Combobox with all value from a MSFlexgrid column

Hello everybody,

I need your help with a code.

In my VB6 form, i have a Combo1 and a MSFLexgrid1. Once my grid populated, i want to feed my combo1 will all text from my MSFlexgrid1, column 2, without doubles.

How can i do this please?

Thanks again for your help.
LVL 11
Wilder1626Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bingieCommented:
Here is a function i made to do this. The function's arguments are the flexgrid that you are reading the data from, the column you are reading the data from, and the combo box where you are outputting the data. This way, you can use one function for many columns, many flexgrids and many combo boxes - without having to hard code different column indexes or object names.
So, if your flexgrid is named MsFlexGrid1, and you are reading from column 2 and your combo box is named Combo1, then you will call this function by:
Call addDistinctItemsToComboFromFlexGrid(MSFlexGrid1, 1, Combo1)

Private Sub addDistinctItemsToComboFromFlexGrid(fg As MSFlexGrid, fgCol As Integer, cbo As ComboBox)

'Create array to hold all the items in the flexgrid column
Dim numRowsInFG
numRowsInFG = fg.Rows
Dim str() As String
ReDim str(numRowsInFG)

'Add all items from the specified fgCol to the array
Dim i As Integer
For i = 0 To fg.Rows - 1
    str(i) = fg.TextMatrix(i, fgCol)
Next i

'Iterate the array and remove duplicates
Dim j As Long
Dim prevIndex As Long
Dim found As Boolean

prevIndex = 0
For i = LBound(str) + 1 To UBound(str)
    found = False
    For j = LBound(str) To i - 1
        If (str(i) = str(j)) Then
            found = True
            Exit For
        End If
    Next j
    If (found = False) Then
        prevIndex = prevIndex + 1
        If (prevIndex <> i) Then
            str(prevIndex) = str(i)
        End If
    End If
Next i

ReDim Preserve str(prevIndex)

'Add the distinct items to the combo box
For i = 0 To UBound(str) - 1
    Combo1.AddItem str(i)
Next i

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wilder1626Author Commented:
Again, a big big thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.