|
-
Mar 29th, 2007, 08:59 AM
#1
Thread Starter
Hyperactive Member
Format multiple mshflexgrid objects
Hello. I want to format 12 diferent mshflexgrid with the same style. Can I do that using a procedure or do I have to format each object ?
Thanks
-
Mar 29th, 2007, 09:02 AM
#2
Re: Format multiple mshflexgrid objects
If you have the formatting code already, then you could do something like
Code:
Private Sub FormatGrid(pmshGridName As MshFlexGrid)
'do formatting using the passed parameter of pmshGridName
End Sub
'then, in your program
FormatGrid Mshflexgrid1
-
Mar 29th, 2007, 09:15 AM
#3
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
Hello Hack. I've tried that, but it just doesn't work. I must say that the grids are in diferent forms because I'm using a MDI project (could it be for that?...).
I've tried something like this:
Code:
Public Sub FormatGrid (FForms as form, FGrid as mshflexgrid)
with fform.fgrid
.....
.....
end with
End Sub
Can I do this, or should i do the formating for each form individually?
Thank you.
-
Mar 29th, 2007, 09:16 AM
#4
Re: Format multiple mshflexgrid objects
If you are going to pass it a form name as well, then the syntax would be
Code:
FormatGrid Form1, MshFlexGrid1
And make is a public sub in module.
-
Mar 29th, 2007, 09:21 AM
#5
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
Yes, I've tried that way... I got the error message: "Compile error: Method or data member not found." Any sugestions?
Thank you again.
-
Mar 29th, 2007, 09:24 AM
#6
Re: Format multiple mshflexgrid objects
On what line of code did the error occur?
-
Mar 29th, 2007, 09:32 AM
#7
Re: Format multiple mshflexgrid objects
Nevermind....I just tested this and got the same error. 
You don't need to pass the form name. Just pass the grid name and you should be fine.
-
Mar 29th, 2007, 09:32 AM
#8
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
Here it goes my code (error line 8) :
vb Code:
Public Sub Grid(GridHistorico As MSHFlexGrid)
Dim i%, j%
Dim r As Long
Dim c As Long
Dim cell_wid As Single
Dim col_wid As Single
With Consultas.GridHistorico '### I got Error Message Here ###
'começa a colorir o fundo da grid
DoEvents
If .Rows < 2 Then Exit Sub 'top row is a header
For j = 1 To .Rows - 1
For i = 1 To .Cols - 1
.Row = j
.Col = i
If j Mod 2 = 0 Then
.CellBackColor = &HFAF5F1 'light green
Else
.CellBackColor = vbWhite
End If
Next i
Next j
.Row = 1
.Col = 1
End With
'formata espaçamento das celulas
For c = 0 To Consultas.GridHistorico.Cols - 1
col_wid = 0
For r = 0 To Consultas.GridHistorico.Rows - 1
cell_wid = TextWidth(Consultas.GridHistorico.TextMatrix(r, c))
If col_wid < cell_wid Then col_wid = cell_wid
Next r
Consultas.GridHistorico.ColWidth(c) = col_wid + 120
Next c
End Sub
Last edited by Hack; Mar 29th, 2007 at 09:54 AM.
Reason: Changed [code] tags for [highlight=vb] tags to get the line numbering
-
Mar 29th, 2007, 09:55 AM
#9
Re: Format multiple mshflexgrid objects
I changed your tags to get the line numbering. Take the form name off. Just use
-
Mar 29th, 2007, 10:05 AM
#10
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
I got the same error...
'formata espaçamento das celulas
For c = 0 To GridHistorico.Cols - 1
col_wid = 0
For r = 0 To GridHistorico.Rows - 1
cell_wid = TextWidth(GridHistorico.TextMatrix(r, c)) '##Error on "TextWidht
If col_wid < cell_wid Then col_wid = cell_wid
Next r
GridHistorico.ColWidth(c) = col_wid + 120
Next c
-
Mar 29th, 2007, 10:11 AM
#11
Re: Format multiple mshflexgrid objects
TextWidth is a method of the Form object. Use
cell_wid = GridHistorico.Parent.TextWidth(GridHistorico...
-
Mar 29th, 2007, 10:11 AM
#12
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
Meanwhile, i've been trying and the color formatation works well. The collumns formt. still doesn't work. I'll keep trying... 
Thanks
-
Mar 29th, 2007, 10:19 AM
#13
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
I've tried but it still not work... same error
Code:
For c = 0 To GridHistorico.Cols - 1
col_wid = 0
For r = 0 To GridHistorico.Rows - 1
cell_wid = TextWidth(GridHistorico.Parent.TextMatrix(r, c)) '##Error on "TextWidht
If col_wid < cell_wid Then col_wid = cell_wid
Next r
GridHistorico.ColWidth(c) = col_wid + 120
Next c
Thanks
-
Mar 29th, 2007, 10:22 AM
#14
Re: Format multiple mshflexgrid objects
TextWidth is a method of the Form.
cell_wid = GridHistorico.Parent.TextWidth(GridHistorico.TextMatrix(r, c))
-
Mar 29th, 2007, 10:32 AM
#15
Thread Starter
Hyperactive Member
Re: Format multiple mshflexgrid objects
Ok, i'm sorry ...
Now is running but the collum enlargment effect is not working very well. Instead of stitching to the text widht , it shrinks to a few pixels. Any clue for that behavior?
Thanks
-
Mar 29th, 2007, 02:13 PM
#16
Re: Format multiple mshflexgrid objects
Unfortunately to be able to resize it accurately you need to do a bit more work than simply using TextWidth.. see the Autosize FlexGrid link in my signature for an explanation of some issues, and a sub that does all of resizing the work for you.
The way you should call it in this case is like this:
Code:
FlexGrid_AutoSizeColumns GridHistorico, GridHistorico.Parent
-
Mar 30th, 2007, 10:35 AM
#17
Thread Starter
Hyperactive Member
[Resolved] Re: Format multiple mshflexgrid objects
Ok, that's it!
You all rock.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|