?? frmtable1.frm
字號:
VERSION 5.00
Begin VB.Form frmtable1
Caption = "table1"
ClientHeight = 5190
ClientLeft = 1110
ClientTop = 345
ClientWidth = 6675
KeyPreview = -1 'True
LinkTopic = "Form5"
ScaleHeight = 5190
ScaleWidth = 6675
Begin VB.CommandButton cmdClose
Cancel = -1 'True
Caption = "關(guān)閉(&C)"
Height = 300
Left = 5340
TabIndex = 0
Top = 3960
Width = 1080
End
Begin VB.PictureBox MSHFlexGrid1
BackColor = &H00FFFFFF&
ForeColor = &H00000000&
Height = 3840
Left = 60
ScaleHeight = 3780
ScaleWidth = 6300
TabIndex = 1
Top = 60
Width = 6360
End
End
Attribute VB_Name = "frmtable1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Const MARGIN_SIZE = 60 ' 單位為緹
' 數(shù)據(jù)綁定變量
Private datPrimaryRS As ADODB.Recordset
' 能列排序變量
Private m_iSortCol As Integer
Private m_iSortType As Integer
Private Sub Form_Load()
Dim sConnect As String
Dim sSQL As String
Dim dfwConn As ADODB.Connection
Dim i As Integer
' 設(shè)置字符串
sConnect = "Provider=MSDASQL.1;Extended Properties='DSN=data;UID=Administrator;PWD=;APP=Visual Basic;WSID=661_064;DATABASE=bus;Trusted_Connection=Yes'"
sSQL = "select 線路,站點(diǎn),順序 from table1 Order by 線路"
' 打開連接
Set dfwConn = New Connection
dfwConn.Open sConnect
' 使用提供的集合創(chuàng)建 recordset
Set datPrimaryRS = New Recordset
datPrimaryRS.CursorLocation = adUseClient
datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
Set MSHFlexGrid1.DataSource = datPrimaryRS
With MSHFlexGrid1
.Redraw = False
' 設(shè)置網(wǎng)格列寬度
.ColWidth(0) = -1
.ColWidth(1) = -1
.ColWidth(2) = -1
' 設(shè)置網(wǎng)格樣式
.AllowBigSelection = True
.FillStyle = flexFillRepeat
' 將標(biāo)頭作成粗體
.Row = 0
.Col = 0
.RowSel = .FixedRows - 1
.ColSel = .Cols - 1
.CellFontBold = True
' 隔行變灰
For i = .FixedRows + 1 To .Rows - 1 Step 2
.Row = i
.Col = .FixedCols
.ColSel = .Cols() - .FixedCols - 1
.CellBackColor = &HC0C0C0 ' 淺灰
Next i
.AllowBigSelection = False
.FillStyle = flexFillSingle
.Redraw = True
End With
End Sub
Private Sub MSHFlexGrid1_DblClick()
'-------------------------------------------------------------------------------------------
' 網(wǎng)格的 DblClick 事件代碼能進(jìn)行列排序
'-------------------------------------------------------------------------------------------
Dim i As Integer
' 僅在單擊固定行時(shí)進(jìn)行排序
If MSHFlexGrid1.MouseRow >= MSHFlexGrid1.FixedRows Then Exit Sub
i = m_iSortCol ' 保存舊列
m_iSortCol = MSHFlexGrid1.Col ' 設(shè)置新列
' 遞增排序類型
If i <> m_iSortCol Then
' 如果在新的列上單擊鼠標(biāo),開始升序排序
m_iSortType = 1
Else
' 如果在相同列單擊鼠標(biāo),則進(jìn)行升序和降序排序的轉(zhuǎn)換。
m_iSortType = m_iSortType + 1
If m_iSortType = 3 Then m_iSortType = 1
End If
DoColumnSort
End Sub
Sub DoColumnSort()
'-------------------------------------------------------------------------------------------
' 作 Exchange-type 排序在列 m_iSortCol
'-------------------------------------------------------------------------------------------
With MSHFlexGrid1
.Redraw = False
.Row = 1
.RowSel = .Rows - 1
.Col = m_iSortCol
.Sort = m_iSortType
.FillStyle = flexFillRepeat
.Col = 0
.Row = .FixedRows
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.CellBackColor = &HFFFFFF
' 隔行變灰
Dim iLoop As Integer
For iLoop = .FixedRows + 1 To .Rows - 1 Step 2
.Row = iLoop
.Col = .FixedCols
.ColSel = .Cols() - .FixedCols - 1
.CellBackColor = &HC0C0C0 ' 淺灰
Next iLoop
.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
' 移動(dòng)“關(guān)閉”按鈕到右下角
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:
' 避免負(fù)值錯(cuò)誤
Resume Next
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -