Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm using ADO to retrieve data using several queries. The data from the
various recordsets is then combined into a two dimensional array that (in this case) has 30 rows and 5 columns. How can I populate an MSHFlexGrid with the data from the two dimensional array? Thanks in advance, Raul |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Raul
The following is one way to populate a grid from a recordset. I have not tied to populate a grid from an array but this may get you going in the right direction.. Obviously you could combine the two loops and of course use with statements. 'Setup column headers MSFlexGrid1.Clear Dim c As Integer MSFlexGrid1.Cols = rs.Fields.Count For c = 0 To rs.Fields.Count - 1 MSFlexGrid1.TextMatrix(0, c) = rs.Fields(c).Name Next 'Populate the the grid Dim r As Integer rs.MoveLast rs.MoveFirst c = 1 MSFlexGrid1.Rows = rs.RecordCount + 1 Do While Not rs.EOF For r = 0 To rs.Fields.Count - 1 MSFlexGrid1.TextMatrix(c, r) = _ rs.Fields(r).Value Next r = r + 1 c = c + 1 rs.MoveNext Loop ' Format the grid MSFlexGrid1.colwidth(0) = 1000 MSFlexGrid1.colwidth(1) = 4000 MSFlexGrid1.ColAlignment(0) = 2 MSFlexGrid1.ColAlignment(1) = 1 MSFlexGrid1.FixedRows = 1 MSFlexGrid1.FixedCols = 0 Good Luck TK "Raul" wrote: I'm using ADO to retrieve data using several queries. The data from the various recordsets is then combined into a two dimensional array that (in this case) has 30 rows and 5 columns. How can I populate an MSHFlexGrid with the data from the two dimensional array? Thanks in advance, Raul |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I really appreciate the help TK.
Thanks a bunch, Raul "TK" wrote: Hi Raul The following is one way to populate a grid from a recordset. I have not tied to populate a grid from an array but this may get you going in the right direction.. Obviously you could combine the two loops and of course use with statements. 'Setup column headers MSFlexGrid1.Clear Dim c As Integer MSFlexGrid1.Cols = rs.Fields.Count For c = 0 To rs.Fields.Count - 1 MSFlexGrid1.TextMatrix(0, c) = rs.Fields(c).Name Next 'Populate the the grid Dim r As Integer rs.MoveLast rs.MoveFirst c = 1 MSFlexGrid1.Rows = rs.RecordCount + 1 Do While Not rs.EOF For r = 0 To rs.Fields.Count - 1 MSFlexGrid1.TextMatrix(c, r) = _ rs.Fields(r).Value Next r = r + 1 c = c + 1 rs.MoveNext Loop ' Format the grid MSFlexGrid1.colwidth(0) = 1000 MSFlexGrid1.colwidth(1) = 4000 MSFlexGrid1.ColAlignment(0) = 2 MSFlexGrid1.ColAlignment(1) = 1 MSFlexGrid1.FixedRows = 1 MSFlexGrid1.FixedCols = 0 Good Luck TK "Raul" wrote: I'm using ADO to retrieve data using several queries. The data from the various recordsets is then combined into a two dimensional array that (in this case) has 30 rows and 5 columns. How can I populate an MSHFlexGrid with the data from the two dimensional array? Thanks in advance, Raul |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Raul wrote: I'm using ADO to retrieve data using several queries. The data from the various recordsets is then combined into a two dimensional array that (in this case) has 30 rows and 5 columns. How can I populate an MSHFlexGrid with the data from the two dimensional array? Do you need the *hierarchical* flexgrid? The MSFlexGrid is designed for two dimensional data. The easiest way to populate it is to use the MSFlexGrid's Clip property with the recordset's GetString method e.g. ' Resize grid MSFlexGrid1.Rows = rs.RecordCount MSFlexGrid1.Cols = rs.Fields.Count ' Select grid area MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1 MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1 ' Copy rs contents to grid MSFlexGrid1.Clip = rs.GetString(adClipString) Jamie. -- |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Jamie
Nice to here from you again. "Jamie Collins" wrote: The easiest way to populate it is to use the MSFlexGrid's Clip property with the recordset's GetString method oh really where did you get that idea "The easiest" "The best" "You should" ???? Raul wrote: I'm using ADO to retrieve data I felt at this point I would try to help the "op" to write the rs to the Grid, not cofusicate the issue. MSFG.... and MSG.... don't care Good Luck TK |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() TK wrote: The easiest way to populate it is to use the MSFlexGrid's Clip property with the recordset's GetString method oh really where did you get that idea I counted the lines of code <g. "The easiest" "The best" "You should" ???? I felt at this point I would try to help the "op" to write the rs to the Grid, not cofusicate the issue. MSFG.... and MSG.... don't care A professional should care about the person who may have to maintain their code. If I use for my 2D array a control designed for hierarchical data, when a 2D equivalent is available, the next guy may wonder, 'Have I missed something? I don't see hierarchical data.' Jamie. -- |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jamie:
Did you notice which control I used in my example? TK "Jamie Collins" wrote: TK wrote: The easiest way to populate it is to use the MSFlexGrid's Clip property with the recordset's GetString method oh really where did you get that idea I counted the lines of code <g. "The easiest" "The best" "You should" ???? I felt at this point I would try to help the "op" to write the rs to the Grid, not cofusicate the issue. MSFG.... and MSG.... don't care A professional should care about the person who may have to maintain their code. If I use for my 2D array a control designed for hierarchical data, when a 2D equivalent is available, the next guy may wonder, 'Have I missed something? I don't see hierarchical data.' Jamie. -- |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() TK wrote: Jamie: Did you notice which control I used in my example? Be honest now: is it really a MSHFlexGrid with a misleading name <g? I've just realised my code assumes the recordcount is available whereas yours works with a forward only cursor, so yours is better. Jamie. -- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|