473,385 Members | 1,908 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,385 software developers and data experts.

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 2364
Try this, untested . . .

Imports System.Windows.Forms
Public Class MyDataGrid
Inherits DataGrid

Public Sub New()
MyBase.New()

End Sub

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal
keyData As Keys) As Boolean
MyBase.ProcessCmdKey(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.RowNumber
Dim rowCount As Integer = CType(Me.DataSource, DataTable).Rows.Count
Dim colNumber As Integer = currentCell.ColumnNumber

If colNumber <> 3 Then
Me.CurrentCell = New DataGridCell(rowNumber, 3)
Else
If rowNumber < rowCount - 1 Then
Me.CurrentCell = New DataGridCell(rowNumber + 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*********@sbcglobal.net> wrote in message
news:%2****************@TK2MSFTNGP10.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****************@TK2MSFTNGP12.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(ByRef msg As Message, ByVal
keyData As Keys) As Boolean
MyBase.ProcessCmdKey(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.RowNumber
Dim rowCount As Integer = CType(Me.DataSource, DataTable).Rows.Count
Dim colNumber As Integer = currentCell.ColumnNumber

If colNumber <> 3 Then
Me.CurrentCell = New DataGridCell(rowNumber, 3)
Else
If rowNumber < rowCount - 1 Then
Me.CurrentCell = New DataGridCell(rowNumber + 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*********@sbcglobal.net> wrote in message
news:%2****************@TK2MSFTNGP10.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
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...
0
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...
1
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...
7
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...
4
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...
1
by: margant | last post by:
Dear Professionals, I have placed my datagrid : .... <asp:Datagrid ID="DGEdu" runat="server" OnDeleteCommand="DGEdu_Remove" OnItemDataBound="DGEdu_ItemDataBound"...
4
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...
6
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...
2
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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
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
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,...

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.