机房进行的差不多了,但是自己的学生上机状态查询总是出现错误,该如何单机选中下机呢?自己想的很好,不就是单机选中,然后flexgrid中的和数据库表中的额内容消失不见吗!
想的很简单,其实做起来也并非很难。
第一想法就是应用相关的鼠标属性,使之单机生效
相关代码:
'用户在窗体或控件鼠标键按下发生 Private Sub MyFlexGrid_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single) With MyFlexGrid .row = .MouseRow nowrow = .row .col = 0 '第一列 .ColSel = .Cols - 1 '确定列数位置,起始列的意思 End With End Sub
'用户在窗体或控件上释放鼠标按键时发生。 Private Sub MyFlexGrid_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single) With MyFlexGrid .RowSel = nowrow '选择第几行 .ColSel = .Cols - 1 End With End Sub
Private Sub mnu_force_Click() Dim txtSQL As String Dim mrc As ADODB.Recordset Dim msgText As String txtSQL = "select * from online_info " Set mrc = ExecuteSQL(txtSQL, msgText) If mrc.EOF = True Then '判断是否有记录 msgbox "已经没有学生上机", vbOKOnly + vbExclamation, "警告" Exit Sub Else mrc.Delete mrc.MoveNext mrc.Close '数据库数据对应删除 MyFlexGrid.RemoveItem MyFlexGrid.row '表格单机删除 End If
相关代码:
Dim txtSQL As String Dim mrc As ADODB.Recordset Dim msgText As String txtSQL = "select * from online_info where cardno='" & Trim(MyFlexGrid.TextMatrix(MyFlexGrid.row, 0)) & "'" Set mrc = ExecuteSQL(txtSQL, msgText) If mrc.EOF = True Then '判断是否有记录 msgbox "已经没有学生上机", vbOKOnly + vbExclamation, "警告" Exit Sub Else mrc.Delete mrc.MoveNext ' mrc.Close '数据库数据对应删除 ' '错误语句: On Error GoTo gpError: MyFlexGrid.RemoveItem MyFlexGrid.row '表格单机删除 gpError: '最后非固定行不删除 If Err.Number = 30015 Then MyFlexGrid.Clear End If End If