2012-12-10 55 views

回答

3

是的,CellValueChanged事件: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx

Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged 
     'do something 
    End Sub 

編輯按您的評論: 是的,你可以在當前值保存到BeginEdit類級別的變量,並在CellValueChanged事件retreieve它:

Private cellValue As String = String.Empty 

Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit 
    cellValue = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString 
End Sub 

Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged 
    MessageBox.Show("row index: " & e.RowIndex & Environment.NewLine & "old value: " & cellValue) 
End Sub 
+0

@Joel Coehoorn謝謝你的工作。另外我怎樣才能得到編輯行的行號?還有什麼辦法獲得舊價值? –

+0

@GeoPaul根據你的評論編輯,我的名字是史蒂夫btw,喬爾是格式化仙女 – Steve

1

但CellValueChanged事件回報每一位的keydown動作,甚至你還沒有完成鍵入消息,這其實是刺激性的。