i have a DGV with 2 columns (data-bound/data from database), column1 is product_name, column2 is price, i have to calculate/sum column2 (price) and give the result in DGV it self (last row of column2), when i use this code :
Using conn As New MySqlConnection("connectionString")
conn.Open()
Dim command As New MySqlCommand("select product_name, price from product", conn)
Dim adapter As New MySqlDataAdapter
Dim dt As New DataTable
adapter.SelectCommand = command
adapter.Fill(dt)
DataGridView1.DataSource = dt
adapter.Dispose()
command.Dispose()
conn.Close()
Dim total As Double
For i As Integer = 0 To DataGridView1.Rows.Count - 1
total = total + DataGridView1.Rows(i).Cells(1).Value
Next
DataGridView1.Rows.Add(total)
End Using
it give me an error : "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
any idea how to solve this?
thanks.
This post has been edited by artemix22: 13 October 2012 - 12:36 AM

New Topic/Question
Reply



MultiQuote





|