Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

I have a userform with a datagridview and its mapped to a database in access. What I want is to, once you click the datagridview to display a userform with the values from the selected row and the to be able to update from the userform and save
Posted

The follow exert will explain how to obtain the values from a datagridview cell double click.

do you need to be able to update the database from the user form or to update the displayed values in the datagridview?


VB
Private Sub DataGridView1_CellDoubleClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
       Dim CellValueA As String = Nothing
       Dim CellValueB As String = Nothing

       CellValueA = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value.ToString
       CellValueA = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value.ToString

       Dim ofrm As New Form2(CellValueA, CellValueB)
       ofrm.show()

   End Sub
 
Share this answer
 
Below code will show you how to get data from datagridview from FORM1 to textbox FORM2

Private Sub DataGridViewX1_DoubleClick(sender As Object, e As System.EventArgs) Handles DataGridViewX1.DoubleClick
FORM2.textbox1.Text = DataGridViewX1.CurrentRow.Cells(1).Value.ToString
FORM2.textbox2.Text = DataGridViewX1.CurrentRow.Cells(2).Value.ToString
End Sub

And you can accomplish update by using sql update statement :

EditRepInvSave.CommandText = "UPDATE [Repair_Inventory] set [User] = '" & textbox1.Text.Trim & "' where id = '" & textbox2.text.trim & "'"
 
Share this answer
 
Please see my article written specially for such cases: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows[^].

—SA
 
Share this answer
 

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