Solved

Problem using Enter key with DataGridView control

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

861 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