DataGridView, how to insert row when EnterKey pressed
-
Hi, I have a data bounded DataGridView control. When I have filled in a row of data on the control I want to save that data to my database table. I want to do the save by hitting the Enter key. Not using a button control. I have several questions .... 1. How do I trap/detect the Enter key? Do I use KeyPress event like this ? ...
private void transactionstblDataGridView\_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { transactionstblTableAdapter.Insert(int,DateTime,decimal,decimal,string,int) { /// }; } }
2. The Adapter.Insert() function in the above is created by Visual Studio. The function parameters list every column of my database table. Two of them are not needed for an Insert/Save because it is defined as auto_increment or as current DateTime (ie use as time_stamp). What do I have to do? How do I do the insert with some parameters left out. Define my own Insert function? 3. How I do detect/know which row on the DataGridView control contains the data I need to save to the database. And thinking ahead, I will do Update, Delete too using the same DataGridView control. Any help is much appreciated Thanks