为什么在DATAGRID上点击右键返回的记录不是当前光标所在的行的记录
本帖最后由 bcrun 于 2013-07-30 11:25:49 编辑 代码如下:
Private Sub mnuDayinPJ3_Click()
On Error GoTo Errc
Call DayinPiaoju(sdrbb.Columns("用户编号"), Val(sdrbb.Columns("操作次数")))
Exit Sub
Errc:
MsgBox ERR.Description
End Sub
Private Sub sdrbb_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single)
On Error GoTo Errc
'实现右键datagrid上被点击的行为当前行
Dim RowValue, ColValue
RowValue = sdrbb.RowContaining(y)
ColValue = sdrbb.ColContaining(X)
If RowValue >= 0 And RowValue <= sdrbb.VisibleRows And _
ColValue >= 0 And ColValue <= sdrbb.VisibleCols Then
sdrbb.Row = RowValue
End If
Adodc1.Recordset.MoveFirst
If RowValue < 0 Then Exit Sub
Adodc1.Recordset.Move RowValue
If Button = 2 Then '如果是鼠标右键按下时
Me.PopupMenu mnuDayinPJ2, 0, X + sdrbb.Left, y + sdrbb.Top '弹出右键菜单
End If
Exit Sub
Errc:
MsgBox ERR.Description
End Sub