Hi guys, I want to multiply or add the values of two or more cells in a datagridview control in a row and and should also be auto-saved in the database after entering datas in the cell. I am using SQL Server 2008 for my database.

Please do take a look at the screenshot attachment that I made for further details..

I don't know what code to use, so I did not put any codes in this discussion.

Thanks guys..

Recommended Answers

All 8 Replies

In the cell leave event of Quantity column multiply the column of item amount and Quantity and set the cell value of total Amount column. And it is nice if u give Save button to save the records..

Thanks for the reply, I will consider putting a save button after the data entry..

My problem is that, I don't know the code for the datagridview to get the value of the selected cell in the current column and row...

Maybe if someone could provide the code snippet, it could help me...


            Dim iCell1 As Integer
            Dim icell2 As Integer
            Dim icellResult As Integer
            iCell1 = DataGridView1.CurrentRow.Cells(1).Value
            icell2 = DataGridView1.CurrentRow.Cells(2).Value
            icellResult = iCell1 * icell2
            DataGridView1.CurrentRow.Cells(3).Value = icellResult

        Catch ex As Exception
        End Try
Make sure the selectionMode is set to cellSelect. Once user leaves the cell 3 it will get the calculated values in it.

Thanks man, I'll try this out and experiment... This really helps me a lot.

how vb DataGridView Auto-calculate cells

DataGridView Auto-calculate cells vb

i tried code to calculate coloumn total amount and reach coloumn amount paid

If dgv.RowCount > 1 Then
            Dim amount As Decimal = 0
            For index As Integer = 0 To dgv.RowCount - 1
                amount += Convert.ToDecimal(dgv.Rows(index).Cells(3).Value)
            TextBox1.Text = amount

        End If

i reached this code after search but with this i only sum the last coloumn values into textbox like you did but i need to sum data from item amount and quantity and in the same time get sum of data in in textbox
hope this code help you

This ia an old thread. Please, make a new thread for your question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.