更新datagrid中的单元格
问题描述:
我正在创建POS系统,但有几件事情我无法让我的销售表单执行。更新datagrid中的单元格
它包含一个包含列代码,描述,数量,总计的表的datagrid视图。
- 代码输入后,我希望它自动加载描述。
- 在输入数量后,我希望它给出该项目的总金额+此订单的总金额。
我有一个查询,这样做,但我不知道如何使该查询返回到特定的细胞中的值。
订单付款后,我希望它以类似收据的方式记录所有数据。 (我不知道如果我应该有一个文本文件,将它记录在一个新表中,创建一个屏幕转储。)然后清理表中的所有内容,以便可以处理新的订单。
这怎么办?
答
处理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