⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grid.cls

📁 金算盘软件代码
💻 CLS
📖 第 1 页 / 共 5 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Grid"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'  GRID类
'  作者:黄涛
'  日期:1998.06.03
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' MSFlexGrid中第0列隐藏,用于存储ID。
' ColData: XXXX XXXX XXXX XXXX XXXX
'           读写 类型 排序 编辑
'                          对象
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit

Const GridReadWrite As Long = 1                                     '读写标志
Const GridReadOnly As Long = 0                                      '只读标志

Const GridNoOrder As Long = 0                                       '没有排序
Const GridAscOrder As Long = 1                                      '升序标志
Const GridDescOrder As Long = 2                                     '降序标志

Const GridUnOrder As Long = 0                                       '不可排序
Const GridOrder As Long = 1                                         '可排序

Const GridTextType As Long = 0                                      '字符类型
Const GridNumericType As Long = 1                                   '数值类型
Const GridDateType As Long = 2                                      '日期类型

Const GridEditText As Long = 1                                      '用EditText编辑
Const GridCalEdit As Long = 2                                      '用CalEdit编辑
Const GridListText As Long = 3                                      '用ListText编辑
Const GridCalendar As Long = 4                                      '用Calendar编辑
Const GridTeditText As Long = 5                                     '用TeditText编辑
Const GridComboBox As Long = 6                                      '用ComboBox编辑

Private WithEvents mclsSubClassFlex As SubClass32.SubClass          'SubClass对象:处理MSFlexGrid对象
Attribute mclsSubClassFlex.VB_VarHelpID = -1
Private WithEvents mclsSubClassEdit As Hook          'SubClass对象:处理EditObject对象
Attribute mclsSubClassEdit.VB_VarHelpID = -1
Private WithEvents mFlex As MSFlexGrid                              'MSFlexGrid对象
Attribute mFlex.VB_VarHelpID = -1
Private mForm As Form                                               'Form对象
Attribute mForm.VB_VarHelpID = -1
Private mclsListSet As ListSet                                      'Grid数据对象
Attribute mclsListSet.VB_VarHelpID = -1

Private mClipRect As RECT                                           'Paint事件矩形区域
Private hdc As Long                                                 'Grid hDC

Private mlngColOfs As Long                                          'Grid中ListSet列开始位置

Private mlngSortedCol As Long                                       '排序列
Private mlngSortedType As Long                                      '排序方式

Private mblnNoRefresh As Boolean                                    '是否需要格式化数据
Private mblnMouseDownOnFixedRow As Boolean                          'MouseDown时位于固定行区域标志
Private mlngMouseDownCol As Long                                    'MouseDown列
Private mblnCancelRowColChange As Boolean                           '取消Grid行列改变事件
Private mblnColResize As Boolean
Private mlngDragOverCol As Long                                     'DragOver列
Private mblnRefresh As Boolean
Private mblnTotal As Boolean
Private mblnSaveList As Boolean
Private mblnRowSel As Boolean
Private mblnColExchange As Boolean
Private WithEvents mEditText As TextBox
Attribute mEditText.VB_VarHelpID = -1
Private WithEvents mCalEdit As CalEdit
Attribute mCalEdit.VB_VarHelpID = -1
Private WithEvents mListText As ListText
Attribute mListText.VB_VarHelpID = -1
Private WithEvents mCalendar As GACALENDARLibCtl.calendar
Attribute mCalendar.VB_VarHelpID = -1
Private WithEvents mTEditText As TEdit
Attribute mTEditText.VB_VarHelpID = -1
Private WithEvents mComboBox As ComboBox
Attribute mComboBox.VB_VarHelpID = -1
Private mEditObject As Control
Private mintRalationCol As Integer
Private mstrRalationValue As String
Private mstrFormat As String
Private mHwndCancel As Long
Private mblnCancel As Boolean
Private mblnEdit As Boolean
Private mEditBox As Control
Private mlngEditRow As Long
Private mlngEditCol As Long

Public Event DataValid(blnCancel As Boolean)
Public Event BeforeEdit(blnCancel As Boolean)
Public Event BeforeSave(blnCancel As Boolean)
Public Event BeforeRefresh(lngRow As Long)
Public Event AfterSort(lngCol As Long)
Public Event AfterSave()
Public Event AfterRefresh(lngRow As Long)
Public Event AfterColResize(lngCol As Long)
Public Event BeforeColChange(blnCancel As Boolean)
Public Event AfterColChange(lngSourCol As Long, lngDestCol As Long)



Private Sub Class_Initialize()
    '创建对象
    Set mclsSubClassFlex = New SubClass32.SubClass
'    Set mclsHookForm = New Hook
    Set mclsListSet = New ListSet
    
    ' MSFlexGrid中第0列隐藏,用于存储ID。
    mlngColOfs = 1
    mblnColExchange = True
    mlngSortedType = 1
End Sub

Private Sub Class_Terminate()
    On Error Resume Next
    If Not mclsListSet Is Nothing And Not mFlex Is Nothing Then
        If mclsListSet.ViewId > 0 And mblnSaveList Then
            GridToListSet
            mclsListSet.SaveList
        End If
    End If
    '撤消对象
    Set mclsSubClassFlex = Nothing
    Set mclsSubClassEdit = Nothing
    Set mclsListSet = Nothing
    Set mEditText = Nothing
    Set mCalEdit = Nothing
    Set mListText = Nothing
    Set mCalendar = Nothing
    Set mTEditText = Nothing
    Set mComboBox = Nothing
    Set mEditObject = Nothing
    If Not mFlex Is Nothing Then Set mFlex = Nothing
End Sub


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'  属性
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Grid属性
Public Property Get Grid() As MSFlexGrid
    Set Grid = mFlex
End Property

Public Property Set Grid(ByVal vNewValue As MSFlexGrid)
    
    '设置Grid
    Set mFlex = vNewValue
    
    '设置SubClass消息
    With mclsSubClassFlex
        If Not mFlex Is Nothing Then
            .hwnd = mFlex.hwnd
            .Messages(WM_PAINT) = True
            .Messages(WM_LBUTTONUP) = True
            .Messages(WM_LBUTTONDOWN) = True
            .Messages(WM_MOUSEMOVE) = True
            .Messages(WM_KEYDOWN) = True
        Else
            .hwnd = 0
            mlngSortedCol = 0
        End If
    End With
End Property

'编辑框
Public Property Get EditText() As Object
    Set EditText = mEditObject
End Property

Public Property Set EditText(ByVal vNewValue As Object)
    
    If TypeOf vNewValue Is TextBox Then
        Set mEditText = vNewValue
        mEditText.Visible = False
        mEditText.Tag = "Saved"
    ElseIf TypeOf vNewValue Is CalEdit Then
        Set mCalEdit = vNewValue
        mCalEdit.Visible = False
        mCalEdit.Tag = "Saved"
    ElseIf TypeOf vNewValue Is ListText Then
        Set mListText = vNewValue
        mListText.Visible = False
        mListText.Tag = "Saved"
    ElseIf TypeOf vNewValue Is GACALENDARLibCtl.calendar Then
        Set mCalendar = vNewValue
        mCalendar.Visible = False
        mCalendar.Tag = "Saved"
    ElseIf TypeOf vNewValue Is TEdit Then
        Set mTEditText = vNewValue
        mTEditText.Visible = False
        mTEditText.Tag = "Saved"
    ElseIf TypeOf vNewValue Is ComboBox Then
        Set mComboBox = vNewValue
        mComboBox.Visible = False
        mComboBox.Tag = "Saved"
    End If
    
    mstrFormat = ""
    mintRalationCol = -1
End Property

'Form属性
Public Property Get Form() As Form
    Set Form = mForm
End Property

Public Property Set Form(ByVal vNewValue As Form)
    Dim lngCnt As Long
    '设置Grid
    Set mForm = vNewValue
    If mblnTotal Then
        For lngCnt = 0 To mFlex.Cols
            If mForm.hlb.UBound < lngCnt Then
                Load mForm.hlb(lngCnt)
                mForm.hlb(lngCnt).Caption = ""
            End If
        Next lngCnt
        TotalRowAdjust
        DrawTotalBox
    End If
    mblnRefresh = True
End Property

'显示合计行
Public Property Get ShowTotal() As Boolean
    ShowTotal = mblnTotal
End Property

Public Property Let ShowTotal(ByVal vNewValue As Boolean)
    mblnTotal = vNewValue
End Property

'结束倥件的Hwnd
Public Property Let HwndCancel(ByVal vNewValue As Long)
    mHwndCancel = vNewValue
End Property

'其他编辑对象
Public Property Set EditBox(ByVal vNewValue As Control)
    Set mEditBox = vNewValue
    mEditBox.Visible = False
End Property

'是否需要格式化数据
Public Property Get FormatData() As Boolean
    FormatData = Not mblnNoRefresh
End Property

Public Property Let FormatData(ByVal vNewValue As Boolean)
    mblnNoRefresh = Not vNewValue
End Property

'IsSelected属性:返回FlexGrid选中行状态。
Public Property Get IsSelected() As Boolean
    '如果MSFlexGrid当前列和选择列为零,无选中行。
    With mFlex
        IsSelected = Not (.col = 0 And .ColSel = 0) And (.Row >= .FixedRows And .Row < .Rows)
    End With
End Property

'列只读属性
Public Property Get ReadOnlyCol(ByVal lngCol As Long) As Boolean
    ReadOnlyCol = False
    With mFlex
        If lngCol >= .FixedCols And lngCol <= .Cols - 1 Then
            If (.ColData(lngCol) And &HF) = GridReadOnly Then
                ReadOnlyCol = True
            End If
        End If
    End With
End Property

Public Property Let ReadOnlyCol(ByVal lngCol As Long, ByVal blnReadOnly As Boolean)
    With mFlex
        If lngCol >= .FixedCols And lngCol <= .Cols - 1 Then
            If ReadOnlyCol(lngCol) <> blnReadOnly Then
                If blnReadOnly Then
                    .ColData(lngCol) = (.ColData(lngCol) And &HFFF0) + GridReadOnly
                Else
                    .ColData(lngCol) = (.ColData(lngCol) And &HFFF0) + GridReadWrite
                End If
            End If
        End If
    End With
End Property


'列类型:0 字符类型(标准)/ 1 数值类型/ 2 日期
Public Property Get ColType(ByVal lngCol As Long) As Integer
    ColType = 0
    With mFlex
        If lngCol >= 1 And lngCol <= .Cols - 1 Then
            ColType = (.ColData(lngCol) And &HF0) \ &H10
        End If
    End With
End Property

Public Property Let ColType(ByVal lngCol As Long, ByVal intType As Integer)
    With mFlex
        If lngCol >= 1 And lngCol <= .Cols - 1 Then
            .ColData(lngCol) = (.ColData(lngCol) And &HFF0F) + intType * &H10
        End If
    End With
End Property

'可排序列:False 不可排序/ True 可排序
Public Property Get ColSort(ByVal lngCol As Long) As Boolean
    ColSort = False
    With mFlex
        If lngCol >= 1 And lngCol <= .Cols - 1 Then
            If (.ColData(lngCol) And &HF00) \ &H100 = GridOrder Then
                ColSort = True
            End If
        End If
    End With
End Property

Public Property Let ColSort(ByVal lngCol As Long, ByVal blnSort As Boolean)
    With mFlex
        If lngCol >= 1 And lngCol <= .Cols - 1 Then
            If blnSort Then
                .ColData(lngCol) = (.ColData(lngCol) And &HF0FF) + &H100
            Else
                .ColData(lngCol) = (.ColData(lngCol) And &HF0FF)
            End If
        End If
    End With
End Property

'列编辑对象类型
Public Property Get EditType(ByVal lngCol As Long) As Integer
    EditType = 0
    With mFlex
        If lngCol >= .FixedCols And lngCol <= .Cols - 1 And .Rows > 1 Then
            EditType = (.ColData(lngCol) And &HF000)
        End If
    End With
End Property

Public Property Let EditType(ByVal lngCol As Long, ByVal intEditType As Integer)
    Dim lngSaveCol As Long, lngSaveColSel As Long
    Dim lngSaveRow As Long, lngSaveRowSel As Long
    
    With mFlex
        If lngCol >= .FixedCols And lngCol <= .Cols - 1 And .Rows > 1 Then
           .ColData(lngCol) = (.ColData(lngCol) And &HFFF) + &H1000 * intEditType
        End If
    End With
End Property

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -