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
Printable View
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
If you have the formatting code already, then you could do something likeCode:Private Sub FormatGrid(pmshGridName As MshFlexGrid)
'do formatting using the passed parameter of pmshGridName
End Sub
'then, in your program
FormatGrid Mshflexgrid1
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:
Can I do this, or should i do the formating for each form individually?Code:Public Sub FormatGrid (FForms as form, FGrid as mshflexgrid)
with fform.fgrid
.....
.....
end with
End Sub
Thank you.
If you are going to pass it a form name as well, then the syntax would beAnd make is a public sub in module.Code:FormatGrid Form1, MshFlexGrid1
Yes, I've tried that way... I got the error message: "Compile error: Method or data member not found." Any sugestions?
Thank you again. :)
On what line of code did the error occur?
Nevermind....I just tested this and got the same error. :sick:
You don't need to pass the form name. Just pass the grid name and you should be fine.
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
I changed your tags to get the line numbering. Take the form name off. Just useCode:With GridHistorico
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
TextWidth is a method of the Form object. Use
cell_wid = GridHistorico.Parent.TextWidth(GridHistorico...
Meanwhile, i've been trying and the color formatation works well. The collumns formt. still doesn't work. I'll keep trying... ;)
Thanks
I've tried but it still not work... same error
ThanksCode: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
TextWidth is a method of the Form.
cell_wid = GridHistorico.Parent.TextWidth(GridHistorico.TextMatrix(r, c))
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 :)
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
Ok, that's it!
You all rock. :wave: