Need help with KeyPress,KeyDown, or KeyUp ... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with KeyPress,KeyDown, or KeyUp ...

skiballskiball Posts: 7Member
I have a listbox on a form which is set by default 'Multiselect = false' which is what i need.

I would like to have when i hold down the 'Shift Key' have the 'MultiSelect = true' and when i release the 'Shift Key' have the 'MultiSelect = false'.

This is what i have:

Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 16 or 17 Then '16 = Shift Key, 17 = Control Key
Me.lvDoc.MultiSelect = True
End If
End Sub

'******The KeyDown Event Works but it seems to stay down and it never goes into the KeyUp Event. ******************************************
_____________________________________________________________________
Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 16 or 17 Then
Me.lvDoc.MultiSelect = false
End If
End Sub

Any help would be greatly appreciated. If you think i should tackle this differently or if i'm doing this wrong then shoot some ideas my way.

Thanks in advance!!!!!

Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : I have a listbox on a form which is set by default 'Multiselect = false' which is what i need.
    :
    : I would like to have when i hold down the 'Shift Key' have the 'MultiSelect = true' and when i release the 'Shift Key' have the 'MultiSelect = false'.
    :
    : This is what i have:
    :
    : Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
    : If KeyCode = 16 or 17 Then '16 = Shift Key, 17 = Control Key
    : Me.lvDoc.MultiSelect = True
    : End If
    : End Sub
    :
    : '******The KeyDown Event Works but it seems to stay down and it never goes into the KeyUp Event. ******************************************
    : _____________________________________________________________________
    : Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
    : If KeyCode = 16 or 17 Then
    : Me.lvDoc.MultiSelect = false
    : End If
    : End Sub
    :
    : Any help would be greatly appreciated. If you think i should tackle this differently or if i'm doing this wrong then shoot some ideas my way.
    :
    : Thanks in advance!!!!!
    :
    :

    You are making a fundamental mistake.

    [code]
    If KeyCode = 16 Or 17 Then
    [/code]

    Here's how it evaluates:
    [code]
    If (KeyCode = 16) Or (17 <> 0) Then
    [/code]

    So this will ALWAYS result in True, because 17 is always <> 0
    So this is how your line ends up:
    [code]
    If (KeyCode = 16) Or (True) Then
    [/code]

    This is the same as:
    [code]
    If True Then
    [/code]



    Greets...
    Richard

  • skiballskiball Posts: 7Member
    : : I have a listbox on a form which is set by default 'Multiselect = false' which is what i need.
    : :
    : : I would like to have when i hold down the 'Shift Key' have the 'MultiSelect = true' and when i release the 'Shift Key' have the 'MultiSelect = false'.
    : :
    : : This is what i have:
    : :
    : : Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
    : : If KeyCode = 16 or 17 Then '16 = Shift Key, 17 = Control Key
    : : Me.lvDoc.MultiSelect = True
    : : End If
    : : End Sub
    : :
    : : '******The KeyDown Event Works but it seems to stay down and it never goes into the KeyUp Event. ******************************************
    : : _____________________________________________________________________
    : : Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
    : : If KeyCode = 16 or 17 Then
    : : Me.lvDoc.MultiSelect = false
    : : End If
    : : End Sub
    : :
    : : Any help would be greatly appreciated. If you think i should tackle this differently or if i'm doing this wrong then shoot some ideas my way.
    : :
    : : Thanks in advance!!!!!
    : :
    : :
    :
    : You are making a fundamental mistake.
    :
    : [code]
    : If KeyCode = 16 Or 17 Then
    : [/code]
    :
    : Here's how it evaluates:
    : [code]
    : If (KeyCode = 16) Or (17 <> 0) Then
    : [/code]
    :
    : So this will ALWAYS result in True, because 17 is always <> 0
    : So this is how your line ends up:
    : [code]
    : If (KeyCode = 16) Or (True) Then
    : [/code]
    :
    : This is the same as:
    : [code]
    : If True Then
    : [/code]
    :
    :
    :
    : Greets...
    : Richard
    :
    :
    Thanks for the reply back. I will fix that mistake but i have still have an issue with the KeyUp Event. I want the MultiSelect to go back to False when the user releases the Shift Key.

    Thanks again,
  • CoryCory Posts: 221Member
    [b][red]This message was edited by Cory at 2005-5-6 11:34:25[/red][/b][hr]
    : : : I have a listbox on a form which is set by default 'Multiselect = false' which is what i need.
    : : :
    : : : I would like to have when i hold down the 'Shift Key' have the 'MultiSelect = true' and when i release the 'Shift Key' have the 'MultiSelect = false'.
    : : :
    : : : This is what i have:
    : : :
    : : : Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
    : : : If KeyCode = 16 or 17 Then '16 = Shift Key, 17 = Control Key
    : : : Me.lvDoc.MultiSelect = True
    : : : End If
    : : : End Sub
    : : :
    : : : '******The KeyDown Event Works but it seems to stay down and it never goes into the KeyUp Event. ******************************************
    : : : _____________________________________________________________________
    : : : Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
    : : : If KeyCode = 16 or 17 Then
    : : : Me.lvDoc.MultiSelect = false
    : : : End If
    : : : End Sub
    : : :
    : : : Any help would be greatly appreciated. If you think i should tackle this differently or if i'm doing this wrong then shoot some ideas my way.
    : : :
    : : : Thanks in advance!!!!!
    : : :
    : : :
    : :
    : : You are making a fundamental mistake.
    : :
    : : [code]
    : : If KeyCode = 16 Or 17 Then
    : : [/code]
    : :
    : : Here's how it evaluates:
    : : [code]
    : : If (KeyCode = 16) Or (17 <> 0) Then
    : : [/code]
    : :
    : : So this will ALWAYS result in True, because 17 is always <> 0
    : : So this is how your line ends up:
    : : [code]
    : : If (KeyCode = 16) Or (True) Then
    : : [/code]
    : :
    : : This is the same as:
    : : [code]
    : : If True Then
    : : [/code]
    : :
    : :
    : :
    : : Greets...
    : : Richard
    : :
    : :
    : Thanks for the reply back. I will fix that mistake but i have still have an issue with the KeyUp Event. I want the MultiSelect to go back to False when the user releases the Shift Key.
    :
    : Thanks again,
    :

    [code]
    Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 16 Or KeyCode = 17 Then Me.lvDoc.MultiSelect = False
    End Sub

    Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 16 Or KeyCode = 17 Then Me.lvDoc.MultiSelect = True
    End Sub
    [/code]

    Should Do It.


  • skiballskiball Posts: 7Member
    : [b][red]This message was edited by Cory at 2005-5-6 11:34:25[/red][/b][hr]
    : : : : I have a listbox on a form which is set by default 'Multiselect = false' which is what i need.
    : : : :
    : : : : I would like to have when i hold down the 'Shift Key' have the 'MultiSelect = true' and when i release the 'Shift Key' have the 'MultiSelect = false'.
    : : : :
    : : : : This is what i have:
    : : : :
    : : : : Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
    : : : : If KeyCode = 16 or 17 Then '16 = Shift Key, 17 = Control Key
    : : : : Me.lvDoc.MultiSelect = True
    : : : : End If
    : : : : End Sub
    : : : :
    : : : : '******The KeyDown Event Works but it seems to stay down and it never goes into the KeyUp Event. ******************************************
    : : : : _____________________________________________________________________
    : : : : Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
    : : : : If KeyCode = 16 or 17 Then
    : : : : Me.lvDoc.MultiSelect = false
    : : : : End If
    : : : : End Sub
    : : : :
    : : : : Any help would be greatly appreciated. If you think i should tackle this differently or if i'm doing this wrong then shoot some ideas my way.
    : : : :
    : : : : Thanks in advance!!!!!
    : : : :
    : : : :
    : : :
    : : : You are making a fundamental mistake.
    : : :
    : : : [code]
    : : : If KeyCode = 16 Or 17 Then
    : : : [/code]
    : : :
    : : : Here's how it evaluates:
    : : : [code]
    : : : If (KeyCode = 16) Or (17 <> 0) Then
    : : : [/code]
    : : :
    : : : So this will ALWAYS result in True, because 17 is always <> 0
    : : : So this is how your line ends up:
    : : : [code]
    : : : If (KeyCode = 16) Or (True) Then
    : : : [/code]
    : : :
    : : : This is the same as:
    : : : [code]
    : : : If True Then
    : : : [/code]
    : : :
    : : :
    : : :
    : : : Greets...
    : : : Richard
    : : :
    : : :
    : : Thanks for the reply back. I will fix that mistake but i have still have an issue with the KeyUp Event. I want the MultiSelect to go back to False when the user releases the Shift Key.
    : :
    : : Thanks again,
    : :
    :
    : [code]
    : Private Sub lvDoc_KeyUp(KeyCode As Integer, Shift As Integer)
    : If KeyCode = 16 Or KeyCode = 17 Then Me.lvDoc.MultiSelect = False
    : End Sub
    :
    : Private Sub lvDoc_KeyDown(KeyCode As Integer, Shift As Integer)
    : If KeyCode = 16 Or KeyCode = 17 Then Me.lvDoc.MultiSelect = True
    : End Sub
    : [/code]
    :
    : Should Do It.
    :
    :
    :
    That was it! You are the man! Thanks!
Sign In or Register to comment.