Howdy, Stranger!

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

Categories

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

skiballskiball Member Posts: 7
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 Member Posts: 2,444
    : 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 Member Posts: 7
    : : 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 Member Posts: 221
    [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 Member Posts: 7
    : [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.