VB之旅-删除FlexGridLevel中选中的行及表中的记录

dim nowRow as integer
Private Sub FlexGridLevel_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With FlexGridLevel
        .Row = .MouseRow    '设置激活单元格的行号为鼠标指针所在行
        nowRow = .Row         '将单元格的行号附给nowRow 因为mousedown和mouseup是两个事件,所以要借助nowRow来传递选中行
        .Col = 0                       '设置单元格激活的列号为0
.Colsel=.Cols-1
    End With
End Sub
Private Sub FlexGridLevel_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With FlexGridLevel
        .RowSel = nowRow '使选中行其呈选中状态
        .ColSel = .Cols - 1    '使选中列其呈选中状态
    End With
End Sub
'删除FlexGridLevel中选中的行及表中的记录
Private Sub cmdDelete_Click()
    Dim mrc As ADODB.Recordset
    Dim txtSQL As String
    Dim MsgText As String
    If FlexGridLevel.RowSel = 0 Then '如果选中行为第一行
        MsgBox "请先选择要删除的用户", vbOKOnly + vbExclamation, "添加删除用户"
    Else
        txtSQL = "delete from user_info where userid='" & Trim(FlexGridLevel.TextMatrix(FlexGridLevel.Row, 0)) & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText) '删除表中记录
        FlexGridLevel.RemoveItem FlexGridLevel.Row '删除选中行
        MsgBox "用户已成功删除", vbOKOnly + vbInformation, "添加删除用户"
    End If
End Sub


你可能感兴趣的:(基于对象编程-VB)