📄 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 = "关闭(&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 ' 单位为缇
' 数据绑定变量
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
' 设置字符串
sConnect = "Provider=MSDASQL.1;Extended Properties='DSN=data;UID=Administrator;PWD=;APP=Visual Basic;WSID=661_064;DATABASE=bus;Trusted_Connection=Yes'"
sSQL = "select 线路,站点,顺序 from table1 Order by 线路"
' 打开连接
Set dfwConn = New Connection
dfwConn.Open sConnect
' 使用提供的集合创建 recordset
Set datPrimaryRS = New Recordset
datPrimaryRS.CursorLocation = adUseClient
datPrimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
Set MSHFlexGrid1.DataSource = datPrimaryRS
With MSHFlexGrid1
.Redraw = False
' 设置网格列宽度
.ColWidth(0) = -1
.ColWidth(1) = -1
.ColWidth(2) = -1
' 设置网格样式
.AllowBigSelection = True
.FillStyle = flexFillRepeat
' 将标头作成粗体
.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()
'-------------------------------------------------------------------------------------------
' 网格的 DblClick 事件代码能进行列排序
'-------------------------------------------------------------------------------------------
Dim i As Integer
' 仅在单击固定行时进行排序
If MSHFlexGrid1.MouseRow >= MSHFlexGrid1.FixedRows Then Exit Sub
i = m_iSortCol ' 保存旧列
m_iSortCol = MSHFlexGrid1.Col ' 设置新列
' 递增排序类型
If i <> m_iSortCol Then
' 如果在新的列上单击鼠标,开始升序排序
m_iSortType = 1
Else
' 如果在相同列单击鼠标,则进行升序和降序排序的转换。
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
' 移动“关闭”按钮到右下角
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:
' 避免负值错误
Resume Next
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -