By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,066 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,066 IT Pros & Developers. It's quick & easy.

Capture Shift-Tab in Datagrid

P: n/a
I've got this working but I've got to wonder if there's not a better

I'm capturing the tab and shift-tab keys in a datagrid and doing
custom processing.

Also, the form designer gets weird when I put in the line:

Me.FileList = New FileListDataGrid(AddressOf HandleTabKey, _
AddressOf HandleShiftTabKey)

It says: "The variable 'FileList' is either undeclared or was never
assigned." It lists many errors but the app runs ok. The FileList
datagird disappears from the designer.

The equivalent line with an empty constructor behaves normally.
Here's the code for the datagrid that handles the shift-tab key.

Thanks Much,
Gene H.

================================================== ==============

Public Class FileListDataGrid
Inherits DataGrid

Private mHandleTabKey As delegateHandleTabKey
Private mHandleShiftTabKey As delegateHandleShiftTabKey

Public Sub New()
End Sub

Public Sub New(ByVal handleTabKey As delegateHandleTabKey, _
ByVal handleShiftTabKey As delegateHandleShiftTabKey)
mHandleTabKey = handleTabKey
mHandleShiftTabKey = handleShiftTabKey
End Sub

Protected Overrides Function ProcessCmdKey(ByRef msg As _
System.Windows.Forms.Message, ByVal keyData As _
System.Windows.Forms.Keys) As Boolean
Static shiftFlag As Boolean 'true if last key was shift

If msg.WParam.ToInt32() = CInt(Keys.Left) Or _
msg.WParam.ToInt32() = CInt(Keys.Right) Then
Return True 'disable left and right arrow keys
End If

If msg.WParam.ToInt32() = CInt(Keys.Tab) Then
If shiftFlag Then
mHandleShiftTabKey() 'shift tab key
shiftFlag = False
mHandleTabKey() 'tab key
End If
Return True
End If

If msg.WParam.ToInt32() = CInt(Keys.ShiftKey) Then
shiftFlag = True
shiftFlag = False
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function
End Class
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.