Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I detect a shift + tab vs just a tab in my datagrid? 1

Status
Not open for further replies.

Blitz

Technical User
Jul 7, 2000
171
US
here is what i currently have in my derived datagrid that detects when tab is pressed and selects the next control.

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean


If msg.WParam.ToInt32() = CInt(Keys.Tab) Then
'goto next tab control
Me.Parent.SelectNextControl(Me, True, True, True, True)
Return True
End If

End Function

this works fine but i now need to be able to detect if the shift key is being held down at the same time as tab so that i can have it go to the previous control, but I dont know what is required to determine if shift is pressed. Thanks for any help


Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean


If msg.WParam.ToInt32() = CInt(Keys.Tab) Then
If 'shift key is pressed' then
'goto previous tab control
Me.Parent.SelectNextControl(Me, False, True, True, True)

Else
'goto next tab control
Me.Parent.SelectNextControl(Me, True, True, True, True)

End If
Return True
End If
End Function
 
Keys is a Flags Enumeration so Tab is 9 and Shift is 65536.

' Try
Dim iKeys As Integer = msg.WParam.ToInt32()
' THINK Bitwise AND/OR/NOT rather than LOGICAL
' If TAB Or Shift Tab
if (iKeys And Not (Keys.Shift)) = (iKeys Or Keys.Tab) Then
' TAB wth or withiout Shift
If iKeys = (Keys.Tab Or Keys.Shift) Then
' Tab and Shift
Me.Parent.SelectNextControl(Me, False, True, True, True)
Else
' Tab only
Me.Parent.SelectNextControl(Me, True, True, True, True)
End If
End If


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Unfortunatly that did not work, it still behaves as if only tab is pressed even if shift is held down. Thanks for trying you gave me a few more ideas to play with.
 
TRY AGAIN.
Except this time use KeyData, not Msg.

' THINK Bitwise AND/OR/NOT rather than LOGICAL
' If TAB Or Shift Tab
if (KeyData And Not (Keys.Shift)) = (KeyData Or Keys.Tab) Then
' TAB wth or withiout Shift
If KeyData = (Keys.Tab Or Keys.Shift) Then
' Tab and Shift
Me.Parent.SelectNextControl(Me, False, True, True, True)
Else
' Tab only
Me.Parent.SelectNextControl(Me, True, True, True, True)
End If
End If


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
That did it thank you for taking the time to help me on this one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top