Haider Noor
Haider Noor

Reputation: 11

updating a cell in datagrid

I am creating a POS system, but there are a couple of things that I cannot get my sales form to do.

It contains a datagrid view of the table containing columns code, description, Qty, total.

  1. After the code has been entered, I want it to load the description automatically.
  2. After the Quantity has been entered, I want it to give the total amount for that Item + the total amount for this order.

I have a query that does this, but I do not know how to make the query return the values on to the specific cell.

After the order has been paid for, I want it to record all the data in an receipt-like way. (I am not sure If I should have a text file, record it on a new table, create a screen dump.) and then clean all the contents of the table, so that a new order can be processed.

How can this be done?

Upvotes: 1

Views: 135

Answers (1)

Meta-Knight
Meta-Knight

Reputation: 17875

Handle the CellValidated event on the DataGridView, then check which column has been validated (using e.ColumnIndex). if that column is either the code or quantity column you can retrieve the value and update the other columns accordingly.

Here's an exemple of how to update description column according to value of code column, assuming a DataGridView called "MyDataGridView", a Code column called "CodeColumn", and a Description column called "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

Upvotes: 1

Related Questions