Solved

Problem using Enter key with DataGridView control

Posted on 2008-06-19
4
416 Views
Last Modified: 2010-04-21
Hi guys,
I have a DataGridView control that is not bound to any underlying data, as I handle that manually.

If I enter some text into a DataGridView cell and press Tab key the focus changes to the next cell and if I also enter some text into that cell a new Row is automatically added to the control.

If however I enter some text into a DataGridView cell as before but press Enter key instead of Tab, the contents of that cell is basically lost and no new row is added.

I was hoping to create a new Row whether I press a Tab or Enter keys. Is that possible and if so, how can I do that?

/Michael
0
Comment
Question by:gem56
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 21823100
And what code do you have ?
0
 

Author Comment

by:gem56
ID: 21823361
The thing is that the application I have is getting fairly large so it's not so easy to extract code but I'll tell you a bit more of what's going on and what I've tried.

I handle DataGridView events such as CellBeginEdit, CellValidating, CellValueChanged, CellClick, CellEnter. For example when I click on a cell I get events such as CellClick and CellBeginEdit. After entering some text if I press Tab key I get CellValidating event but if I press Enter instead, I don't get CellValidating event.

Sorry for not being able to send you code, as it's scattered and fairly extensive, but I hope the above paragraph gives you a bit more info, even though it's not very much.

If you want me to try something and let you know of the result I'd be happy to do that ?

/Michael
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 250 total points
ID: 21826715
As you may know it's dificult to help you that way but I will try.

If your problem is when you're editing the cell and press enter key instead of tab you can do this (in the snippet) to change the behavior of the handle keys. This overrides the ProcessCmdKey() changing the TAB key with ENTER key. Maybe this way all the events that you use now keeps running.

I really don't understand why the CellValidating is not running ... it should work on bouth examples that you give me.

Check if this heps
   Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

        If keyData = Keys.Enter And Me.DataGridView1.IsCurrentCellInEditMode Then

            SendKeys.Send("{TAB}")

            Return True

        Else

            Return MyBase.ProcessCmdKey(msg, keyData)

        End If

    End Function

Open in new window

0
 

Author Closing Comment

by:gem56
ID: 31468802
Thanks, you've given me ideas to try.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

21 Experts available now in Live!

Get 1:1 Help Now