[2008] Procedure preventing DGV cell edit
Code:
Private Sub dgvMasterHumidor_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvMasterHumidor.CellEndEdit
Me.MHBind.EndEdit()
CigarTotal()
Dim varTtlVle As New OleDb.OleDbCommand("UPDATE MasterHumidor SET TotalValue = @TtlVle", Me.Conn)
Dim Quantity As Integer = CInt(Me.dgvMasterHumidor.CurrentRow.Cells("Quantity").Value)
Dim Price As Double = CDbl(Me.dgvMasterHumidor.CurrentRow.Cells("Price").Value)
Dim Total As Double = CDbl(Quantity * Price)
varTtlVle.Parameters.AddWithValue("@TtlVle", Total)
Me.Conn.Open()
varTtlVle.ExecuteNonQuery()
Me.MHDS.Tables("MasterHumidor").Clear()
MHadapter.Fill(Me.MHDS, "MasterHumidor")
Me.Conn.Close()
'Dim TestTotal As Double = CDbl(Me.dgvMasterHumidor.CurrentRow.Cells("TotalValue").Value)
'MsgBox(TestTotal)
End Sub
The above code shouldn't be to difficult to figure out even if it is a round-a-bout way of accomplishing what I want to do. I am working on a better way, but for now I am stumped on a speed bump in the road.
The code multiplies the value in the quantity column by the value in the price column and updates the TotalValue column of the database. The Dataset is then cleared and re-filled using the new information. The bottom two lines are commented out but if I uncomment them, they actually work and with the correct value.
The problem is that now when I edit the quantity and hit enter the quantity doesn't actually change. Even if I uncomment the last two lines, the msgbox returns the product of the two columns (using the newly inserted quantity) but the quantity reverts back to the original number afterwards.
Re: [2008] Procedure preventing DGV cell edit
can you tell if it is actually updating the database?
I see that you are updating the table, then refilling your dataset..... but I don't think that will affect the grid... I think you need to re-bind it in order for it to show the changes....
That said... I don't think that's an ideal way to update the info in the first place. I think you might be better off updating the data right into the grid, then using the DataSet.Update method to get the data back into the database. ALSO.... you are updating the TotalValue of ALL ROWS in your table.... did you know that?
-tg