473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trapping Enter key in dataGrid cell

Hello All,
I'm trying to trap the enter key in my dataGrid using the event...
aColumnTextColumn.TextBox.KeyPress += new
KeyPressEventHandler(DateKeyPress);

The event fires when there is a key pressed for the cell except for the
Enter key. Apparently this key doesn't fire this event. My event code is...
private void DateKeyPress(object sender, KeyPressEventArgs e)
{
Console.WriteLine(e.KeyChar);
switch ((char)(e.KeyChar))
{
case '\r': //Enter key
e.Handled = true;
break;

default: // Everything else
e.Handled = false;
break;
}
}

When I modify a cell's value and press the Enter key, my break point on the
e.Handled = true; for case '\r': doesn't even hit. Can someone tell me what
I'm doing wrong?

Thanks
Nov 16 '05 #1
1 2680
Hello Randy,

You can't trap the Enter keystroke this way. What you need is inheriting
from the grid control and overriding its methods such as ProcessDialogKey,
ProcessCmdKey and ProcessKeyPreview. I can't remember which of them is
exatcly responsible for the Enter key, you will have to experiment :-(

I can however assure you that it is possible to intercept practically every
keystroke to force the user to stay in a cell unless she enters a correct
value. Hopefully knowing it IS possible will give you enough motivation for
research :-)

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Randy" <te**@temp.com> wrote in message
news:eI**************@TK2MSFTNGP15.phx.gbl...
Hello All,
I'm trying to trap the enter key in my dataGrid using the event...
aColumnTextColumn.TextBox.KeyPress += new
KeyPressEventHandler(DateKeyPress);

The event fires when there is a key pressed for the cell except for the
Enter key. Apparently this key doesn't fire this event. My event code
is...
private void DateKeyPress(object sender, KeyPressEventArgs e)
{
Console.WriteLine(e.KeyChar);
switch ((char)(e.KeyChar))
{
case '\r': //Enter key
e.Handled = true;
break;

default: // Everything else
e.Handled = false;
break;
}
}

When I modify a cell's value and press the Enter key, my break point on
the e.Handled = true; for case '\r': doesn't even hit. Can someone tell
me what I'm doing wrong?

Thanks


Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
1
by: Byron McClain | last post by:
.... is being consumed. I added an event handler for the "keypress" event and my delegate never gets executed. Why? I am trying to catch the "enter" key pressed event to prevent the DataGrid...
3
by: Mike L | last post by:
For a Data Grid in a Win Form, when the user selects a row and then presses the Enter key, how do I capture that the user pressed the enter key?
10
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total...
4
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
8
by: OHM | last post by:
I know this is not purely a VB.NET question, but I thought I would ask tho ! First create a typed-dataset with an integer ID primary-key field and a string Name field. Then create a form with a...
4
by: tg | last post by:
Visual Studio 2003 My problem is that I am dynamically creating a datagrid on pageload. The datagrid is completely dynamic as it is based on the number of columns returned from a recordset. The...
3
by: Melson | last post by:
hi can anyone help me how can i capture ENTER keystroke when the cell in datagrid is in editing mode. I'm now creating a data entry form with primary key in header and details in datagrid. So...
2
by: benfly08 | last post by:
Hi, everyone. I got a weird problem for my C# program. In my program, I use a DataGrid to display data. I bind the DataGrid to a DataTable. I made all the cells in DataGrid ReadOnly as True. So...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.