Results 1 to 2 of 2

Thread: [2008] Procedure preventing DGV cell edit

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    [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.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width