Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transferring data between two MSFlexGrids using For next loop 3

Status
Not open for further replies.

iojbr

Technical User
Feb 12, 2003
129
US
Hi:

I have two MSFlexGrids a VB Form. The first flexgrid (MSFlexGrid1) is populated from an ADO recordset. Column 6 of this flexgrid ("UnitsOrdered") is empty at first, but is editible by using a combo box. After selecting values (1, 2, 3 etc...) for certain cells in column 6, using the combo box, I want to transfer those rows, whose Column 6 value "is not null", to a second flexgrid. How would I be able to do that that dosen't involve creating another recordset from MSFlexGrid1. Thanks a lot for your help.
 
Have a look at the textmatrix property (think that's it's name)
It allows you to reference grid entries via the row and column.


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Use the property nigelrivett mentioned with two nested for loops (one for rows and one for columns). For each row check if it meets your criteria before looping through the columns. Keep a separate variable to track which row you are on in the second grid because it will vary from the first grid.

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
Here is some code (without much comments) for you to see how to access cells of the flexgrid ... help it helps!

Private Function LOADflxRESULTS() As Long
Dim iNCol As Integer, iNRow As Integer 'Number of Col and Rows in rst
Dim iC As Integer, iR As Integer 'Col and Row counters
LOADflxRESULTS = 0 'INIT function RETURN
[AppProcs].OpenCNN cnn
rst.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText
If rst.EOF And rst.BOF Then
flxR.Rows = 0:: flxR.Cols = 0:: flxR.Clear 'Wipe out grid
lblResultCount.Visible = True
lblResultCount.Caption = "(No records matched search criteria)"
GoTo LOADflxRESULTS_CloseOut
End If
rst.MoveLast:: rst.MoveFirst
lblResultCount.Visible = True
LOADflxRESULTS = rst.RecordCount
lblResultCount.Caption = "(" & rst.RecordCount & " records matched search criteria)"
'can't close either the rst or the cnn here since rst not truly declared as a disconnected
'recordset.

iNCol = rst.Fields.Count
iNRow = rst.RecordCount
flxR.Cols = iNCol:: flxR.Rows = iNRow + 1 'define grid size
flxR.FixedCols = 1:: flxR.FixedRows = 1 'establish grey col and row
rst.MoveFirst
For iC = 0 To iNCol - 1 'Label Col Headings
flxR.TextMatrix(0, iC) = rst.Fields(iC).Name
Next iC
For iR = 1 To iNRow
For iC = 0 To iNCol - 1
If IsNull(rst.Fields(iC).Value) Then
flxR.TextMatrix(iR, iC) = ""
Else
flxR.TextMatrix(iR, iC) = rst.Fields(iC).Value
End If
Next iC
rst.MoveNext
Next iR
LOADflxRESULTS_CloseOut:
rst.Close
cnn.Close
End Function '(LOADflxRESULTS)

 
Hey Guys:

Thanks for all your help. I went ahead and created two nested for next loops, using two variables (column and row)
along with Textmatrix property, like you said, and it worked perfectly. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top