473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with DataGrid Navigation / Cancelling Keystroke in PreviewKeyDown Event

I'm noticing that when my DataGrid has focus, it handles the Enter key by
advancing to the next row in the grid. This neutralizes Forms's current
defined AcceptButton.

My primary question: is there any quick way to configure the Grid not to
handle the Enter key? I do not see any property control which might
configure this behavior.

My secondary question: If there's no quick solution via Grid configuration,
then how do I get the following workaround to work? I've implemented the
PreviewKeyDown event to trap for the Enter key. This is working, but only
partially. Using this approach, the AcceptButton is triggered, however I
need to then suppress the Enter key so that the Grid doesn't handle it.
However, I don't see anything in the PreviewKeyDownE ventArgs object to allow
me to cancel the keystroke.

private void gridResults_Pre viewKeyDown(obj ect sender,
PreviewKeyDownE ventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.AcceptButt on.PerformClick ();
}
}

Thanks for any help which you can provide.

- Joseph Geretz -
Mar 15 '07 #1
1 5270
OK, I was able to implement this successfully using the KeyDown event,
rather than the PreviewKeyDown event.

private void gridResults_Key Down(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.AcceptButt on.PerformClick ();
e.Handled = true;
}
}

Kind of leaves me wondering though, what's the point in the PreviewKeyDown
event if you can't cancel the key? What would be a scenario where you'd need
to implement KeyDownPreview as opposed to KeyDown?

Thanks,

- Joe Geretz -

"Joseph Geretz" <jg*****@nospam .comwrote in message
news:uV******** ******@TK2MSFTN GP03.phx.gbl...
I'm noticing that when my DataGrid has focus, it handles the Enter key by
advancing to the next row in the grid. This neutralizes Forms's current
defined AcceptButton.

My primary question: is there any quick way to configure the Grid not to
handle the Enter key? I do not see any property control which might
configure this behavior.

My secondary question: If there's no quick solution via Grid
configuration, then how do I get the following workaround to work? I've
implemented the PreviewKeyDown event to trap for the Enter key. This is
working, but only partially. Using this approach, the AcceptButton is
triggered, however I need to then suppress the Enter key so that the Grid
doesn't handle it. However, I don't see anything in the
PreviewKeyDownE ventArgs object to allow me to cancel the keystroke.

private void gridResults_Pre viewKeyDown(obj ect sender,
PreviewKeyDownE ventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.AcceptButt on.PerformClick ();
}
}

Thanks for any help which you can provide.

- Joseph Geretz -

Mar 15 '07 #2

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

Similar topics

1
1866
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. One of the main problems at this point lies in cancelling the event. I have found that the TAB fires the onkeypress in NN, but not in IE. I can...
8
602
by: InvisibleDuncan | last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message box that warns that their changes will be lost, and asks them to confirm whether to continue. Sounds simple Unfortunately, the ListView's...
7
1789
by: DraguVaso | last post by:
Hi, I have a Datagrid, and I want to limit the Lenght of the text in a certain column to a certain number of characters (for exemple 10). What I want is that, when the user is typing in the column, that he can't type more than the 10 characters (not that they are concattenated during input or something like that). Anybody any idea?
2
2211
by: Greg T | last post by:
Hi, I have a rather long form that I don't want people submitting unless they are absolutely sure they are ready. I figured the easiest way to prevent an accidental form submission by way of hitting of the enter key was to simply not have a submit button, instead going for a regular anchor which calls a javascript confirmation box and...
0
1476
by: shravan | last post by:
Hi, I have a extended Windows Forms Datagrid, I have custom column styles defined for it. The problem is when I am in the new row and pressing escape two times - First time it's cancelling cell changes - Second time it's cancelling row changes it's doing this for all rows except for first row, whenever I am calling escape twice for a newly...
1
2037
by: melanieab | last post by:
Hi again, I have a textbox where the text is longer than the textbox width. When I type something in there or even do any single keystroke (other than tab, up, down, or enter) and then leave, the beginning of the string shows, and focus goes on to the next box. But if I just tab through or want to go straight to the next textbox, the...
18
3308
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to the image. The desired behavior is that when the pop-up is invoked, I want the underlying window to stay put. I don't have this problem when I...
10
2943
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C 22222 D E F 33333 G H I 44444 J K L
9
4026
by: pvsundarram | last post by:
hey, i am trying to cancel the keydown event for certain keycodes( for eg:- enter key ).But the cancelling of this event is not happening in firefox. Is there any way to cancel the event in the iframe. CODE ===== <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ...
0
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6022
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.