Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default How do I use MSHFlexGrid?

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   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default How do I use MSHFlexGrid?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default How do I use MSHFlexGrid?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default How do I use MSHFlexGrid?


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   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default How do I use MSHFlexGrid?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default How do I use MSHFlexGrid?


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   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default How do I use MSHFlexGrid?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default How do I use MSHFlexGrid?


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"