How do I use MSHFlexGrid?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 said:
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.

--
 
Hi Jamie

Nice to here from you again.

Jamie Collins said:
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" ????


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
 
TK said:
oh really
where did you get that idea

I counted the lines of code said:
"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.

--
 
TK said:
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.

--
 
jamie
Be honest now: is it really a MSHFlexGrid with a misleading name <g>?

Ill admit you had me wondering which control I use
but then I realized I tested the code and it would have
been looking for an object if I used the MSHF. I have
used those controls extensive in Visual Basic so they are
pretty familiar. Remember to pick the yellow one. I m not
sure what benefit you would gain using a grid in an excel
app unless you just wanted to view the information and
the data bound control “DataGrid†that does have edit
capability is not available on my more controls list. You
could of course use the routine of superimposing a textbox
over a cell to make it appear that you are actually editing the
cell, but you already can do that on a sheet.

Good Luck
TK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top