473,403 Members | 2,293 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,403 software developers and data experts.

How to handle the DataGrid KeyUp events?

I’m using a DataGrid control on my form; and I want to handle the KeyUp event.
So I did:
myDataGrid.KeyUp += new KeyEventHandler(this.OnKeyUp);

When the DataGrid is empty, I mean when It has no data so now rows are seen,
all keys are causing my this.OnKeyUp(...) to be invoked correctly.

But when the DataGrid is populated with some data (rows are seen with only
DataGridTextBoxes), only several keys are causing it to be invoked.

I assumed that the DataGridTextBox which were added are stealing the KeyUp
events. So I also did:
myDataGrid.ControlAdded += new ControlEventHandler(this.OnControlAdded);
private void OnControlAdded(object sender, ControlEventArgs e)
{
e.Control.KeyUp += new KeyEventHandler(this.OnKeyUp);
}

But still the this.OnKeyUp(...) is not invoked.

I noticed that the myDataGrid.Controls.Count value is greater then the
number of times my OnControlAdded(...) is invoked. So for every control in
myDataGrid.Controls I also did:
foreach( Control ctrl in m_dataGrid.Controls )
{
ctrl.KeyUp += new KeyEventHandler(this.OnKeyUp);
}
But still the results are the same.
Can anybody tell me how can I get and handle the keys events (KeyUp,
KeyDown, ...) of my DataGrid?
----------
Thanks
Sharon
Nov 17 '05 #1
3 3091
Ok, I found the problem.

The DataGridTextBox do steal the events because they also steal the focus.
So I did:
(1) myDataGrid.KeyUp += new KeyEventHandler(this.OnKeyUp);
(2) myDataGrid.ControlAdded += new ControlEventHandler(this.OnControlAdded);
(3) private void OnControlAdded(object sender, ControlEventArgs e)
{
e.Control.Enter += new EventHandler(this.OnEnter);
}
(4) void OnEnter (object sender, EventArgs e)
{
If( myDataGrid.Focus = false )
{
myDataGrid.Focus();
}
}

And now my this.OnKeyUp(...) handler is not correctly.
---------
Regards
Sharon
Nov 17 '05 #2
Sorry, I have an error in the text I poster in the last line, instead:

And now my this.OnKeyUp(...) handler is invoked correctly.
Nov 17 '05 #3
VJ
Sharon

Check this link out.. http://64.78.52.104/FAQ/WinForms/default.asp#44

VJ

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:CA**********************************@microsof t.com...
Sorry, I have an error in the text I poster in the last line, instead:

And now my this.OnKeyUp(...) handler is invoked correctly.

Nov 17 '05 #4

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

Similar topics

1
by: Omavlana | last post by:
Pleas advise me how to do validations in side datagrid before updating the details into database. I am using VB.NET and updating the datagrid using sqlcommandbuilder. I want to validate the...
4
by: john sutor | last post by:
When moving up and down with the arrow keys on my DataGrid, I cannot get either the Keypress, KeyUp or KeyDown events to respond. I am putting breakpoints in to capture the event but they never...
4
by: Serdge Kooleman | last post by:
How to get "Key press" event when i'm working with DataGrid (winforms). Seems to me that standard events "KeyUp, KeyPress" are ignored :-( Thank you
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
0
by: Gidi | last post by:
Hi, I'm trying to make a keyUp and KeyDown events on dataGrid cell which combaind with DataTable. I saw in the internet few examples (like this one:...
0
by: WhiteWizard | last post by:
I have a windows app that requires I use the Microsoft Datagrid. My users would like to be able to select multiple rows using the Shift and Ctrl keys, and the datagrid has the selection...
0
by: WhiteWizard | last post by:
I am trying to implement standard multi-select of rows in a datagrid. That is, allow the user to use the CTRL & SHIFT keys to select multiple rows in a datagrid. Then I'll loop through them and...
1
by: fiaolle | last post by:
Hi I have a DataGrid with comboboxes and I'm woundering what runs when a user clicks in the DataGrid or ComboBox. When I choose something in the combobox with the KeyUp event nothing happens, but...
2
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.