Edit current row only in DataGridView

Hellow experts,

In my current project I have created a DataGridView that shows a File Structure that is created by the application based upon reading a text file with delimiters.  The user can optionally change the structure as needed.

I have three buttons: Add, Edit, and Delete.  These pertain to each row in the File Structure datagrid called DGVStructure.  I have decided to use a DataGridView because I can eliminate the need for another form for record editing.

For example: If I add a new row I have it setup so that the cursor moves to the new row and enables editing.  I do not want the customer moving from this row until they either cancel the record addition or his ENTER to save the newly added row.

I have seen some solutions about KeyPress and KeyDown.  Could you give me some assistance on creating the code needed that will now allow movement from the current row until it is either cancelled or saved?

Thanks for the assistance!
Peter AllenAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CodeCruiserConnect With a Mentor Commented:
You can trap the enter key using the datagridview's keydown event.
0
 
CodeCruiserCommented:
I dont think it would be possible unless you extend the datagridview. Even then, the user could move the focus away using the mouse.
0
 
Peter AllenAuthor Commented:
If the focus was moved away from the record which was just added, or edited then could the focus then be pointed back to the cells that were recently added or edited?

My reason for picking the DataGridView were the ease for the user to add new columns and see the characteristics in one neat form control.

The other option I suppose I could use is a separate tab for the specific fields and one for the DataGridView.
0
 
CodeCruiserCommented:
Yes you can refocus the edit controls if the focus moves away but it would  be a bit complex as you would have to manually bind event handlers to the editing textboxes inside the datagrid. Another option is to use separate controls with the event handlers and use buttons to enable editing and update records.
0
 
Peter AllenAuthor Commented:
OK How about this. :

If I select to Add or Edit records in the structure then the grid is in edit mode.  I can move among the rows and make the necessary changes.  Once I hit the ENTER key the datagridview is set to read-only.    How do I go about checking for the specific ENTER key?  Can I use the RowLeave event for this?

I don't want to have to add another tab with controls so I am going to accept that once in Edit mode the user will be able to change any of the rows until the ENTER key or Save button are pressed.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.