raiye Posted February 5, 2004 Posted February 5, 2004 Hello Everybody I am using a Datagrid in my WindowsForms with C#. I am facing a strange problem. I have a hidden menu in my form so that when I press ctrl+S the menu is fired and my code tries to save the record in the datagrid. Suppose I enter a new row in the datagrid and without leaving the row press Ctrl+S it always gives me an error message because in my database I have a not null constraint. However if after entering a new row I click on Ctrl+S the new changes are saved automatically. Even If I use the Save button to save the new row it works fine, the problem only occurs when I press Ctrl+S without moving to another row in the datagrid. Any help will be appreciated. Quote
Moderators Robby Posted February 5, 2004 Moderators Posted February 5, 2004 Perhaps in the event of Ctl+S move focus to another control or another row in the grid. Quote Visit...Bassic Software
raiye Posted February 6, 2004 Author Posted February 6, 2004 Hi Robby, Thanks for your suggestion, I tried this out and this works fine in case there are more than one records in the datagrid. But what if there are no rows in the datagrid and the User is adding a record for the first time. Quote
I Schobert Posted February 6, 2004 Posted February 6, 2004 Try to move the focus away from the cell that has been edited by the user. For example: MyGrid.CurrentCell = New DataGridCell(MyGrid.CurrentCell.RowNumber, 1) That should do the trick ... Quote IS
raiye Posted February 7, 2004 Author Posted February 7, 2004 Hi, I tried out moving the focus to another cell in the grid but even that doesnt seem to work. Quote
I Schobert Posted February 9, 2004 Posted February 9, 2004 More Info Hey Raiye, Maybe you can provide the code section that you use to fire your "save" functionality. Also, let me know where in this code the error occurs. IS Quote IS
raiye Posted February 11, 2004 Author Posted February 11, 2004 Hi, What I have done is that have created a menu in the form which has the shortcut Ctrl+S for Save. So automatically when on a grid the User presses Ctrl+S the menu event is fired and it runs the procedure for saving the record. But since the User still is on the same cell which he has edited the changes have not been reflected into the grid and so in the save record it doesnt get the value. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.