473,703 Members | 3,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Key events in datagrid control

Is there any way to reliably catch KeyUp events for Function keys in
particular while inside a datagrid?

I have a form with KeyPreview=True and I am using the Form.KeyUp event to
handle several function keys (F5, F6, etc.)

The problem is I have a datagrid on this form and it seems whenever the
datagrid has the focus, it consumes most of the key events without passing
them on to me. I have tried using a DataGridTextBox control, which helps
but it only gives some F-keys and only the KeyDown events (and occasioally
KeyPress) It does not provide any KeyUp events (except, for some reason,
the F10 key). For example, using the DataGridTextBox I can get the KeyDown
for F1 and F3 but not F2, and KeyUp does not occur for any of these keys.

Thanks,
-Carl

Nov 20 '05 #1
2 2373
Try this, untested . . .

Imports System.Windows. Forms
Public Class MyDataGrid
Inherits DataGrid

Public Sub New()
MyBase.New()

End Sub

Protected Overrides Function ProcessCmdKey(B yRef msg As Message, ByVal
keyData As Keys) As Boolean
MyBase.ProcessC mdKey(msg, keyData)
Const WM_KEYDOWN As Int32 = &H100
Const WM_SYSKEYDOWN As Int32 = &H104

If msg.Msg = WM_KEYDOWN Or msg.Msg = WM_SYSKEYDOWN Then
Select Case keyData
Case Keys.Enter
Dim currentCell As DataGridCell = Me.CurrentCell
Dim rowNumber As Integer = currentCell.Row Number
Dim rowCount As Integer = CType(Me.DataSo urce, DataTable).Rows .Count
Dim colNumber As Integer = currentCell.Col umnNumber

If colNumber <> 3 Then
Me.CurrentCell = New DataGridCell(ro wNumber, 3)
Else
If rowNumber < rowCount - 1 Then
Me.CurrentCell = New DataGridCell(ro wNumber + 1, 3)
Else
Me.CurrentCell = New DataGridCell(0, 3)
End If
End If
End Select
End If
End Function

End Class

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Carl Tribble" <ca*********@sb cglobal.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is there any way to reliably catch KeyUp events for Function keys in
particular while inside a datagrid?

I have a form with KeyPreview=True and I am using the Form.KeyUp event to
handle several function keys (F5, F6, etc.)

The problem is I have a datagrid on this form and it seems whenever the
datagrid has the focus, it consumes most of the key events without passing
them on to me. I have tried using a DataGridTextBox control, which helps
but it only gives some F-keys and only the KeyDown events (and occasioally
KeyPress) It does not provide any KeyUp events (except, for some reason,
the F10 key). For example, using the DataGridTextBox I can get the KeyDown for F1 and F3 but not F2, and KeyUp does not occur for any of these keys.

Thanks,
-Carl

Nov 20 '05 #2
Works great! Thank you very much, OHM.

-Carl
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Try this, untested . . .

Imports System.Windows. Forms
Public Class MyDataGrid
Inherits DataGrid

Public Sub New()
MyBase.New()

End Sub

Protected Overrides Function ProcessCmdKey(B yRef msg As Message, ByVal
keyData As Keys) As Boolean
MyBase.ProcessC mdKey(msg, keyData)
Const WM_KEYDOWN As Int32 = &H100
Const WM_SYSKEYDOWN As Int32 = &H104

If msg.Msg = WM_KEYDOWN Or msg.Msg = WM_SYSKEYDOWN Then
Select Case keyData
Case Keys.Enter
Dim currentCell As DataGridCell = Me.CurrentCell
Dim rowNumber As Integer = currentCell.Row Number
Dim rowCount As Integer = CType(Me.DataSo urce, DataTable).Rows .Count
Dim colNumber As Integer = currentCell.Col umnNumber

If colNumber <> 3 Then
Me.CurrentCell = New DataGridCell(ro wNumber, 3)
Else
If rowNumber < rowCount - 1 Then
Me.CurrentCell = New DataGridCell(ro wNumber + 1, 3)
Else
Me.CurrentCell = New DataGridCell(0, 3)
End If
End If
End Select
End If
End Function

End Class

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Carl Tribble" <ca*********@sb cglobal.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is there any way to reliably catch KeyUp events for Function keys in
particular while inside a datagrid?

I have a form with KeyPreview=True and I am using the Form.KeyUp event to handle several function keys (F5, F6, etc.)

The problem is I have a datagrid on this form and it seems whenever the
datagrid has the focus, it consumes most of the key events without passing them on to me. I have tried using a DataGridTextBox control, which helps but it only gives some F-keys and only the KeyDown events (and occasioally KeyPress) It does not provide any KeyUp events (except, for some reason, the F10 key). For example, using the DataGridTextBox I can get the

KeyDown
for F1 and F3 but not F2, and KeyUp does not occur for any of these keys.
Thanks,
-Carl


Nov 20 '05 #3

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

Similar topics

3
3120
by: Sharon | last post by:
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.
0
1403
by: Daniel Armstrong | last post by:
Hello, I have a usercontrol that I have built that has a single generic datagrid. When setting up the inital properties I build the template columns for the datagrid dynamically so it can display as readonly or readwrite. The readwrite displays link buttons for edit, update, cancel and delete buttons. When I click on a edit link button the page using the usercontrol will begin it's page load event and then the usercontrol page load...
1
7582
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
7
2275
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the Datagrid that will fire off when the Checkbox is changed? regards /Lars
4
1325
by: JJ | last post by:
Hi, I was wondering is it possible to create my own html table that has two features. 1. it is databound and 2. create my own events for it? The datagrid is nice and I do use it but I need to be able to customize it for other events to occur with it. Thanks,
1
2039
by: margant | last post by:
Dear Professionals, I have placed my datagrid : .... <asp:Datagrid ID="DGEdu" runat="server" OnDeleteCommand="DGEdu_Remove" OnItemDataBound="DGEdu_ItemDataBound" OnItemCommand="DGEdu_OnItemCommand" AutoGenerateColumns="false"
4
2132
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
6
1749
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost datagrid's OnItemDataBound() method we check for the row in which it's appropriate to add the secondary datagrid. Exactly one row in the topmost grid will contain the secondary grid.
2
2218
by: jock1up | last post by:
I am working with editing within a DataGrid control cell and am confused about which events occur after the editing is completed. I see that 5 events can occur total, including the ones below and AfterColEdit, AfterUpdate. 1. BeforeColUpdate/ 2. AfterColUpdate/ 3. BeforeUpdate or all of these occur? 1. BeforeColUpdate says after editing is completed in a cell, but before dates is moved from the cell to the DataGrid control's copy...
0
8662
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9243
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9109
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7853
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4420
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.