Public Sub FormataGrelhas(Grelha As MSHFlexGrid, Formulario As Form)
Dim i%, j% 'variaveis da formatação de cores das linhas
Dim r As Long '\
Dim c As Long ' \ variaveis da formatação da largura das celulas
Dim cell_wid As Single ' /
Dim col_wid As Single '/
On Local Error Resume Next
With Grelha 'COMEÇA FORMATAÇÃO
.Refresh
.Redraw = False
DoEvents 'começa a colorir o fundo da grid
If .Rows < 2 Then Exit Sub 'top row is a header
For j = 1 To .Rows - 1
For i = 0 To .Cols - 1
.Row = j
.Col = i
If j Mod 2 = 0 Then
.CellBackColor = &HFAF5F1 'azul claro
Else
.CellBackColor = vbWhite
End If
Next i
Next j
.Row = 1
.Col = 1
End With
'formata espaçamento das celulas
For c = 0 To Grelha.Cols - 1
col_wid = 0
For r = 0 To Grelha.Rows - 1
cell_wid = Formulario.TextWidth(Grelha.TextMatrix(r, c))
If col_wid < cell_wid Then col_wid = cell_wid
Next r
Grelha.ColWidth(c) = col_wid + 120
Next c
Grelha.Redraw = True
End Sub