Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

Posted

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 ...

IS
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...