Solved

Edit current row only in DataGridView

Posted on 2008-10-14
5
794 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
ID: 22718929
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
ID: 22720164
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
ID: 22720480
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
ID: 22720882
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
ID: 22720896
You can trap the enter key using the datagridview's keydown event.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with Syntax 9 36
VB 2005 Tooltips on Form Load Event 15 29
Creating a route in asp.net webforms 2 25
Help with adding DLL file in Windows project 20 28
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

786 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