In my program I have a DataGridView which shows a table of orders. I want when a user changes a number in the quantity column, for my program to update the price column either after the user has left the cell or when they click 'Update Order'.
I could use a sub (as below) to change the price column after the quantity cell value has changed.
I then need code in this sub to work out the prices.
This is my code I have to work out pricing. At the moment it only works for labels/textboxes. I need for it to be able to work for cells in a DataGridView, so txtQty.Text is a cell from the quantity column. I need this code to loop through each row in the DataGridView.
My DataGridView is populated by the following code.
Can anyone help me? I'm really stuck.
I could use a sub (as below) to change the price column after the quantity cell value has changed.
VB.NET:
Private Sub dataGridView1_CellValueChanged(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles OrderGrid.CellValueChanged
I then need code in this sub to work out the prices.
This is my code I have to work out pricing. At the moment it only works for labels/textboxes. I need for it to be able to work for cells in a DataGridView, so txtQty.Text is a cell from the quantity column. I need this code to loop through each row in the DataGridView.
VB.NET:
product = cDBProduct.GetProduct(lblArtNo.Text)
If txtQty.Text >= product.Qd5 Then
lblSubtotal.Text = CStr((CDbl(product.DisPrice5) / 100) * CDbl(txtQty.Text))
ElseIf txtQty.Text >= product.Qd4 Then
lblSubtotal.Text = CStr((CDbl(product.DisPrice4) / 100) * CDbl(txtQty.Text))
ElseIf txtQty.Text >= product.Qd3 Then
lblSubtotal.Text = CStr((CDbl(product.DisPrice3) / 100) * CDbl(txtQty.Text))
ElseIf txtQty.Text >= product.Qd2 Then
lblSubtotal.Text = CStr((CDbl(product.DisPrice2) / 100) * CDbl(txtQty.Text))
ElseIf txtQty.Text >= product.Qd1 Then
lblSubtotal.Text = CStr((CDbl(product.DisPrice1) / 100) * CDbl(txtQty.Text))
ElseIf txtQty.Text < product.Qd1 Then
lblSubtotal.Text = CStr((CDbl(product.SalPrice) / 100) * CDbl(txtQty.Text))
End If
My DataGridView is populated by the following code.
VB.NET:
Dim connection As OleDbConnection = DBconnect.GetConnection2
Dim selectStatement As String = "SELECT cusorders.* FROM cusorders;"
Dim da As New OleDbDataAdapter(selectStatement, connection)
Dim CmdB As New OleDbCommandBuilder(da)
Dim DS As New DataSet
da.Fill(DS, "Table1")
OrderGrid.DataSource = DS.Tables("Table1").DefaultView
OrderGrid.Refresh()
Cursor.Current = Cursors.Default
Can anyone help me? I'm really stuck.