Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Thank you for your time in advance, I need help, I want to create a DataGridView in Windows form, and in this grid I want to enter data and when I hit enter it should save that data to database and create another line, I tried to find a good tutorial on it but didn’t succeeded. if there is any good example please let me know
Posted

C#
void dataGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        // Handle your transaction to DB here
    }     
}
 
Share this answer
 
Comments
kasheer 3-Oct-14 7:24am    
Dear Gihan I was asking for a complete example, I've no previous experience with this thing... Please!!
Dilan Shaminda 3-Oct-14 13:10pm    
why you can't insert your data to db inside the above code block? normally when you hit enter on datagridview it will go to a new line.

check this link if you have any doubts regarding inserting data to database

How to: Insert New Records into a Database
kasheer 3-Oct-14 14:18pm    
Dear Dilan I know how to save data in to db, and I'm thankful for your time, but that is not what I want, I mean in the end this will happen, what I want is: I don't want to use any sort of button, the data is entered in the grid columns and when pressed enter key that is saved to db, I've done other stuff like save data in in to grid on button click but not when there is just grid.
for example please see this screen short screen shot
Dilan Shaminda 3-Oct-14 23:02pm    
kasheer 9-Oct-14 13:45pm    
thank you Dilan I'll try this one, it seems good ;)
 
Share this answer
 
Comments
kasheer 9-Oct-14 13:44pm    
that was never my 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