Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can we edit datagridview by keypress event.
Mean if I add on row in datagrid and press enter key then the data in the last row should be added to the database.
Posted
Comments
Manoj Kumar Choubey 4-Apr-12 8:47am    
Is this Windows form or Web form ....
Kschuler 4-Apr-12 12:11pm    
The short answer is Yes. The long answer would require more information, like are you using data binding and/or how are you connecting your grid to your database data. Why don't you post the relevant code you've tried to accomplish this with and tell us why it isn't working or what errors you get.
dcba1 5-Apr-12 2:12am    
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim tmpSmptmsgk As Integer
Dim strSQL As String
Dim tmpgkmax As Integer
Dim tmpgkhlthplbm As Integer
Dim tmpsmtpmsnnm As String
If e.KeyData = Keys.Enter Then
tmpgkhlthplbm = gtgkeybydtls("HlthPrblmnm", cmbhlth.Text, "hlthprblm", "HlthPrblmgk")
Dim tmprwcnt As Integer
tmprwcnt = smptGridView1.RowCount - 1
tmpsmtpmsnnm = smptGridView1.Item(0, tmprwcnt - 1).Value
tmpSmptmsgk = gtgkeybydtls("Smptmsnm", smptGridView1.Item(0, tmprwcnt - 1).Value, "smptms", "Smptmsgk")
If tmpgkhlthplbm <> 0 Then
If tmpsmtpmsnnm <> "" Then
rs.Open("select * from smptms where Smptmsgk='" & tmpSmptmsgk & "'", con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
If Not rs.EOF Then
rs1.Open("select * from hlthprblmssmptms where Smptmsgk='" & tmpSmptmsgk & "' and HlthPrblmgk='" & tmpgkhlthplbm & "'", con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
If Not rs.EOF Then
Else
strSQL = "insert into hlthprblmssmptms (HlthprblmsSmptmsgk, HlthPrblmgk,Smptmsgk,Rfrncgk) values('" & tmpgkmax & "','" & tmpgkhlthplbm & "','" & tmpSmptmsgk & "')"
con.Execute(strSQL)
End If
rs1.Close()
refresh_main_frm()
Else
tmpgkmax = getMaxNo("Smptmsgk", "smptms")
tmpSmptmsgk = tmpgkmax
strSQL = "Insert into smptms (Smptmsgk, Smptmsnm) values ('" & tmpgkmax & "','" & smptGridView1.Item(0, tmprwcnt - 1).Value & "')"
con.Execute(strSQL)
rs1.Open("select * from hlthprblmssmptms where Smptmsgk='" & tmpSmptmsgk & "' and HlthPrblmgk='" & tmpgkhlthplbm & "'", con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
If rs.EOF Then
strSQL = "insert into hlthprblmssmptms (HlthprblmsSmptmsgk, HlthPrblmgk,Smptmsgk) values('" & tmpgkmax & "','" & tmpgkhlthplbm & "','" & tmpSmptmsgk & "')"
con.Execute(strSQL)
End If
rs1.Close()
refresh_main_frm()
End If
rs.Close()
End If
End If
End If



this is my code. I have one datagrid and I to perform event when I change data on grid and press enter key.
Tejas Vaishnav 6-Apr-12 0:46am    
please use improve question functionality if you provide more detail for your question.

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