How can one put MSHFlexgrid data from 2 flexgrids into a single grid using VB6?

I have 3 VB6 MSHFlexGrids. Grid1 and Grid2 have data, Grid3 is blank.
[1] I want to put all the data from Grid1---say, 30 rows---into Grid3.
[2] I then want to append all the Grid2 data onto the end of the Grid3 data that just came from #1 as stated above.
[3] The amount of data in Grid1 and Grid2 will vary, so the code should consider looking for the first blank row of Grid3 when doing #2 above
[4] We're not talking a huge amount of data in Grid1 or Grid2----about 20 to 30 rows or in each grid would be the maximum

How can I do this? Most of the information I can find talks about 'combining' data in cells or rows----I just want to make one contiguous set of records in Grid3. Many thanks in advance for any assistance.
LVL 4
jazjefAsked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
Here's some code. Note that in the "Fill Grid3" part it assumes that if any cell in a grid is blank, then that's the end of the data in that grid.

Dim r As Integer
Dim c As Integer
Dim intNewRow As Integer

' Generate test data
For r = 0 To 10
    For c = 0 To Grid1.Cols - 1
        Grid1.TextMatrix(r, c) = r * c
    Next
Next
For r = 0 To 5
    For c = 0 To Grid2.Cols - 1
        Grid2.TextMatrix(r, c) = r * c + 5
    Next
Next

' Fill Grid3
For r = 0 To Grid1.Rows - 1
    For c = 0 To Grid1.Cols - 1
        If Grid1.TextMatrix(r, c) <> "" Then
            intNewRow = r + 1
            Grid3.TextMatrix(r, c) = Grid1.TextMatrix(r, c)
        End If
    Next
Next

For r = 0 To Grid2.Rows - 1
    For c = 0 To Grid2.Cols - 1
        If Grid2.TextMatrix(r, c) <> "" Then
            Grid3.TextMatrix(intNewRow, c) = Grid2.TextMatrix(r, c)
        End If
    Next
    intNewRow = intNewRow + 1
Next

Open in new window

0
 
Martin LissOlder than dirtCommented:
I'll create a demo project for you. Be back soon.
0
 
jazjefAuthor Commented:
Works perfectly MartinLiss.....MANY thanks once again. I just set Grid3 rows to equal Grid1 rows + Grid2 rows so Grid3 always has room for the transaction.
0
 
Martin LissOlder than dirtCommented:
Once again you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.