Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem using Enter key with DataGridView control

Posted on 2008-06-19
4
Medium Priority
?
428 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 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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