處理DataGridView上的CellValidated事件,然後檢查哪個列已被驗證(使用e.ColumnIndex)。如果該列是代碼或數量列,則可以檢索該值並相應地更新其他列。
下面是如何根據代碼列的值來更新說明列,假設名爲「MyDataGridView」的DataGridView,稱爲「CodeColumn」一個代碼列的爲例,和說明列稱爲「DescriptionColumn」:
Private Sub MyDataGridView_CellValidated(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs) Handles MyDataGridView.CellValidated
If e.ColumnIndex = CodeColumn.Index Then
Dim code As String = MyDataGridView(e.ColumnIndex, e.RowIndex).Value.ToString()
Dim description As String = ' Get description using code '
MyDataGridView(DescriptionColumn.Index, e.RowIndex).Value = description
End If
End Sub
非常感謝.. 請你舉個足以舉個例子嗎? – 2011-04-04 16:07:23
我用一個例子編輯了我的答案。 – 2011-04-04 16:30:23