处理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