前端之家收集整理的这篇文章主要介绍了
VB之旅-删除FlexGridLevel中选中的行及表中的记录,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<span style="font-family:SimHei;font-size:24px;">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,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</span>