We help IT Professionals succeed at work.

How do I add consecutive items to a MSFlexGrid using VB6?

I'm using VB6---This code will add an item to row 1 column 1 of the flexgrid... how do I add other items in this same column but always in the next row down.

Dim i As Integer
   
    For i = 0 To i
        If Not MSFlexGrid1.TextMatrix(i, 1) > "" Then
           MSFlexGrid1.TextMatrix(i + 1, 1) = Text1.Text
        End If
    Next i

Here's what I get right now in column 1 row 1 when I put a color into Text1 and click my button:

Red

Here's what I want in column 1 row i each time I enter a color in Text1 and click the button:

Red
Blue
Orange
Yellow
Blue
Green
Red

...... and so on......

Thanks for any help.....



Comment
Watch Question

Retired
Top Expert 2012
Commented:
Try this
Private Sub Command1_Click()
    Dim i As Integer
    
    For i = 1 To MSFlexGrid1.Rows - 1
    If MSFlexGrid1.TextMatrix(i, 1) = "" Then
        MSFlexGrid1.TextMatrix(i, 1) = Text1.Text
        Exit For
        End If
    Next i
    
    If i = MSFlexGrid1.Rows Then
        MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
        MSFlexGrid1.TextMatrix(i, 1) = Text1.Text
    End If
End Sub

Open in new window

Author

Commented:
Thanks for the help GrahamSkan....works like a charm.