Solved

Problem using Enter key with DataGridView control

Posted on 2008-06-19
4
427 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

617 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