1

当您移动到另一个单元格时,检查当前行的正确条件是什么。

我试试这段代码:

Private Sub Legal_RecordsDataGridView_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Legal_RecordsDataGridView.CurrentCellChanged

    if Legal_RecordsDataGridView.CurrentRow.Index = Legal_RecordsDataGridView.CurrentCellAddress.Y then

        msgbox("changed")
        else
        msgbox("no")

    endif
End Sub

我总是得到“否”的结果,因为它们总是具有相同的索引。

当我移动到另一个单元格时,如何检查CurrentRow索引是否相同,例如当我移动到另一个单元格但我想要结果的同一行no但当我移动到另一个单元格时,就像我在column1 但我移到 column2 但不同的行然后结果是changed

我希望你明白我的意思!

4

3 回答 3

1

尝试在 CurrenCellChanged 事件之后获取行索引..

例如..

Private Sub Legal_RecordsDataGridView_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Legal_RecordsDataGridView.CurrentCellChanged

'Add the condition here..
'Say, what's the value of last row index? If you don't have a value for last row index, then exit sub


'get here the last row index (set the variable), this should give you the row index that you can use in your next cell change event..
mynewrowindex = Legal_RecordsDataGridView.currentrow.index

End Sub
于 2013-08-28T03:28:44.353 回答
0

试试这个代码

mRow_Leave是一个全局变量

Dim mRow_Leave as integer


Private Sub DataGridView1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellChanged

        If mRow_Leave = DataGridView1.CurrentCell.RowIndex Then

            MsgBox("no")
        Else
            MsgBox("change")
        End If
        mRow_Leave = DataGridView1.CurrentCell.RowIndex
    End Sub

Private Sub DataGridView1_RowLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowLeave

   mRow_Leave = e.RowIndex

End Sub
于 2013-04-04T07:08:41.267 回答
0
Private Sub Legal_RecordsDataGridView_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Legal_RecordsDataGridView.CurrentCellChanged

    if Legal_RecordsDataGridView.cells.Index = Legal_RecordsDataGridView.CurrentCellAddress.Y then

        msgbox("changed")
        else
        msgbox("no")

    endif
End Sub
于 2013-04-04T07:26:00.240 回答