我如何知道单元格的值是否已更改而不丢失 DataGridView 中的焦点
How can I know if a value of a cell has changed without losing the focus in DataGridView
我正在验证 DataGridView
的单元格,我希望如果您更改值而不更改另一个单元格输出一条消息。
我认为您需要 CellLeave 事件。 Docs
Private Sub dataGridView1_CellLeave(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles dataGridView1.CellLeave
If (String.IsNullOrEmpty(dataGridView1(e.ColumnIndex, e.RowIndex).Value)) Then
MessageBox.Show("Error", "Cell Empty!")
End If
End Sub
此外,我认为在失去焦点之前进行验证并没有很大的优势,因为在执行任何其他操作时它无论如何都会失去焦点。 (不太习惯VB.net有错请指正)
我正在验证 DataGridView
的单元格,我希望如果您更改值而不更改另一个单元格输出一条消息。
我认为您需要 CellLeave 事件。 Docs
Private Sub dataGridView1_CellLeave(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles dataGridView1.CellLeave
If (String.IsNullOrEmpty(dataGridView1(e.ColumnIndex, e.RowIndex).Value)) Then
MessageBox.Show("Error", "Cell Empty!")
End If
End Sub
此外,我认为在失去焦点之前进行验证并没有很大的优势,因为在执行任何其他操作时它无论如何都会失去焦点。 (不太习惯VB.net有错请指正)