I'm trying to find a solution to a problem. I have added two columns of datagridview to a project of VB.net. 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
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try 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) con.Open() cmd.ExecuteNonQuery() con.Close() End If Next MsgBox("Data added successfully") Catch ex As Exception MsgBox(ex.Message) Finally If (con.State = ConnectionState.Open) Then con.Close() 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 dt.Clear() da.Fill(dt) DataGridView1.DataSource = dt dt.Columns.Add("Qty") dt.Columns.Add("value") End Sub Like Product_Name Purchase_Rate Qty Value p1 5 2 10
Dim cmd As New SqlCommand("select a.Product_Name,a.Purchase_Rate from tbl_Pro a", con)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)