3/2/11

DataGridViewRow cell click

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim r As New DataGridViewRow If DataGridView1.Rows.Count > 0 Then r = DataGridView1.Rows(e.RowIndex) TextBox1.Text = r.Cells(0).Value TextBox2.Text = r.Cells(1).Value TextBox3.Text = r.Cells(2).Value price.Text = r.Cells(3).Value / r.Cells(2).Value End If End Sub

Save Data Grid Data

If DataGridView1.Rows.Count > 0 Then Dim r As DataGridViewRow For Each r In DataGridView1.Rows Dim db As New DBAccess Dim strSQL As String strSQL = "INSERT INTO [dbo].[Table_2] ([name1] ,[id1]) VALUES ( '" & r.Cells(0).Value & "'," & r.Cells(3).Value & " )" db.ExecuteScalar(strSQL, Data.CommandType.Text) db.CloseDB() Next End If