Solved

Problem using Enter key with DataGridView control

Posted on 2008-06-19
4
426 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
[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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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