0

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

Attachments dgv.png 52.16 KB
5
Contributors
8
Replies
70
Views
5 Years
Discussion Span
Last Post by Shark_1
Featured Replies
  • 1

    [CODE] Try 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 MessageBox.Show(ex.ToString) End Try Make sure the selectionMode is set to cellSelect. Once user leaves the cell 3 it … Read More

0

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

0

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


Thanks

1
Try
            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
            MessageBox.Show(ex.ToString)
        End Try
Make sure the selectionMode is set to cellSelect. Once user leaves the cell 3 it will get the calculated values in it.
0

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

0

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)
            Next
            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 question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.