?
Solved

Edit current row only in DataGridView

Posted on 2008-10-14
5
Medium Priority
?
802 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 total points
ID: 22720896
You can trap the enter key using the datagridview's keydown event.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

764 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