Click here to Skip to main content
15,072,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to find a solution to a problem. I have added two columns of datagridview to a project of I want - when I give a number in the second column, the product of the number in my first column with this number will be displayed in the third column(
Multiplication). Like working in MS Excel.
Will it be possible? Although the correct result is being added to my database but the data is not being displayed in Gridview. I want to see the product of two columns in the datagridview.
I would have benefited if an experienced person had wasted his precious time and assisted me in this matter. Thanks

What I have tried:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  For Each row As DataGridViewRow In DataGridView1.Rows
   Dim select1 As Boolean = Convert.ToBoolean(row.Cells("checkboxcolomn").Value)
   If select1 Then
  Dim cmd As New SqlCommand("insert into tbl_Purchase (Product_Name,PurChase_Rate,Qty,Value) values(@d2,@d3,@d4,@d5)", con)
 cmd.Parameters.AddWithValue("@d2", row.Cells("Product_Name").Value)
 cmd.Parameters.AddWithValue("@d3", row.Cells("Purchase_Rate").Value)
 cmd.Parameters.AddWithValue("@d3", row.Cells("Qty").Value)
cmd.Parameters.AddWithValue("@d5", row.Cells("Qty").Value * row.Cells("Purchase_Rate").Value)
 End If
 MsgBox("Data added successfully")
Catch ex As Exception
If (con.State = ConnectionState.Open) Then
End If
End Try
End Sub

Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
Dim cell1 As DataGridViewCheckBoxCell = DataGridView1.Rows(e.RowIndex).Cells(0)
cell1.Value = True

 Private Sub frm_purchase_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 Dim checkboxcolumn As New DataGridViewCheckBoxColumn()
 checkboxcolumn.HeaderText = "*"
 checkboxcolumn.Name = "checkboxcolomn"
 DataGridView1.Columns.Insert(0, checkboxcolumn)

 Dim cmd As New SqlCommand("select a.Product_Name,a.Purchase_Rate from tbl_Pro a", con)
 Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable
DataGridView1.DataSource = dt

 End Sub

Product_Name    Purchase_Rate    Qty     Value
    p1		          5		      2	      10	
Updated 17-Sep-21 5:02am
jewel serniabad 17-Sep-21 10:18am
Sorry Two Column Not Rows
Richard MacCutchan 17-Sep-21 10:24am
You can correct your question by using the Improve question link above.
Member 15329613 17-Sep-21 10:47am
You say that the value is being updated in the database, then are you showing that column in your gridivew?
jewel serniabad 17-Sep-21 12:11pm
Product, 5, 2, 10 (5*2)

1 solution

If the right value is shown in your DB, why not fetch it when you load your DGV? At the moment you only fetch two values:
Dim cmd As New SqlCommand("select a.Product_Name,a.Purchase_Rate from tbl_Pro a", con)
Just add the third ...
jewel serniabad 17-Sep-21 12:05pm
When I give data input in the third column, I want to see the result of the product of the third column and the second column in the fourth column immediately. .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900