codice:
Private Const MARGIN_SIZE = 60 ' in twip
' variabili per l'associazione di dati
Private datPrimaryRS As ADODB.Recordset
Private Sub Form_Load()
Dim sConnect As String
Dim sSQL As String
Dim dfwConn As ADODB.Connection
Dim i As Integer
' imposta le stringhe
sConnect = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;User ID=Admin;Data Source=magicolotto.mdb;Mode=Share Deny None;Extended Properties=';COUNTRY=0;CP=1252;LANGID=0x0409';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Database Password='';Jet OLEDB:Global Partial Bulk Ops=2"
sSQL = "select ID,Data,BA1,BA2,BA3,BA4,BA5,CA1,CA2,CA3,CA4,CA5,FI1,FI2,FI3,FI4,FI5,GE1,GE2,GE3,GE4,GE5,MI1,MI2,MI3,MI4,MI5,NA1,NA2,NA3,NA4,NA5,PA1,PA2,PA3,PA4,PA5,RO1,RO2,RO3,RO4,RO5,TO1,TO2,TO3,TO4,TO5,VE1,VE2,VE3,VE4,VE5 from archivio"
' apre la connessione
Set dfwConn = New Connection
dfwConn.Open sConnect
' crea un gruppo di record utilizzando l'insieme specificato
Set datPrimaryRS = New Recordset
datPrimaryRS.CursorLocation = adUseClient
datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
Set MSHFlexGrid1.DataSource = datPrimaryRS
With MSHFlexGrid1
Dim cel As Integer
For cel = 2 To 51
.Redraw = False
' imposta la larghezza delle colonne della griglia
.ColWidth(0) = 690
.ColWidth(1) = -1
.ColWidth(cel) = 450
Next cel
' definisce le impostazioni per l'ordinamento e l'unione delle colonne della griglia
For i = 0 To .Cols - 1
.MergeCol(i) = True
Next i
.Sort = flexSortGenericAscending
' imposta lo stile della griglia
.AllowBigSelection = True
.FillStyle = flexFillRepeat
' formatta l'intestazione in grassetto
.Row = 0
.Col = 0
.RowSel = .FixedRows - 1
.ColSel = .Cols - 1
.CellFontBold = True
' formattazione in grigio a colonne alterne
For i = .FixedCols To .Cols() - 1 Step 2
.Col = i
.Row = .FixedRows
.RowSel = .Rows - 1
.CellBackColor = &HC0C0C0 ' grigio chiaro
Next i
.AllowBigSelection = False
.FillStyle = flexFillSingle
.Redraw = True
End With
End Sub
Private Sub Form_Resize()
Dim sngButtonTop As Single
Dim sngScaleWidth As Single
Dim sngScaleHeight As Single
On Error GoTo Form_Resize_Error
With Me
sngScaleWidth = .ScaleWidth
sngScaleHeight = .ScaleHeight
' sposta il pulsante di chiusura nell'angolo in basso a destra
With .cmdClose
sngButtonTop = sngScaleHeight - (.Height + MARGIN_SIZE)
.Move sngScaleWidth - (.Width + MARGIN_SIZE), sngButtonTop
End With
.MSHFlexGrid1.Move MARGIN_SIZE, _
MARGIN_SIZE, _
sngScaleWidth - (2 * MARGIN_SIZE), _
sngButtonTop - (2 * MARGIN_SIZE)
End With
Exit Sub
Form_Resize_Error:
' impedisce la generazione di errori nel caso di valori negativi
Resume Next
End Sub