Solved

Edit current row only in DataGridView

Posted on 2008-10-14
5
791 Views
Last Modified: 2008-10-20
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!
0
Comment
Question by:Peter Allen
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
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
 

Author Comment

by:Peter Allen
Comment Utility
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
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
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
 

Author Comment

by:Peter Allen
Comment Utility
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 125 total points
Comment Utility
You can trap the enter key using the datagridview's keydown event.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now