Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shift Lock

Posted on 1998-12-09
4
Medium Priority
?
298 Views
Last Modified: 2010-05-03
Is there a way to simulate a Shift Lock key in VB5 or VB6? When the up or down arrow keys are pressed for my listbox control, I want the previously selected lines to remain selected - just as if I were holding down the shift key.
0
Comment
Question by:MattTriv
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:jjbyers
ID: 1449071
You always want to multi-select?
0
 

Author Comment

by:MattTriv
ID: 1449072
No. Only when I am simulating the Shift Lock. The list's multiselect property is set to 'extended' and that's fine. Here's what I want to accomplish: Often, there is occasion to select many items in the list one by one. Now, the way that is done is by holding down the shift key and pressing the down arrow key over and over. I want the convenience of not having to hold the shift key down.
0
 
LVL 3

Accepted Solution

by:
jjbyers earned 1230 total points
ID: 1449073
Put a checkbox and a list box on a form

paste the following code

Option Explicit

Private Sub Form_Load()
Dim i As Integer
  For i = 1 To 100
    List1.AddItem i
  Next i
End Sub

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
   If Check1 Then
    If KeyCode = 40 Then
      List1.Selected(List1.ListIndex) = True
      List1.Selected(List1.ListIndex + 1) = True
      KeyCode = 0
    ElseIf KeyCode = 38 Then
      List1.Selected(List1.ListIndex) = True
      List1.Selected(List1.ListIndex - 1) = True
      KeyCode = 0
    End If
  End If
End Sub

when the checkbox is selected the up and down arrow keys will act as if shifted.

hope this helps.
0
 

Author Comment

by:MattTriv
ID: 1449074
I had to make some additions to your code, but setting KeyCode to zero is what I needed to learn, so I've got it working the way I want. Thanks for your help. Here is the modified code:

Option Explicit

Private Sub Form_Load()
Dim i As Integer
  For i = 0 To 10
    List1.AddItem i
  Next i
End Sub

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    If Check1 Then
        If KeyCode = 40 Then
            KeyCode = 0
            If List1.ListIndex = List1.ListCount - 1 Then Exit Sub
            If List1.Selected(List1.ListIndex + 1) Then
                List1.Selected(List1.ListIndex) = False
                List1.ListIndex = List1.ListIndex + 1
            Else
                List1.Selected(List1.ListIndex) = True
                List1.Selected(List1.ListIndex + 1) = True
            End If
        ElseIf KeyCode = 38 Then
            KeyCode = 0
            If List1.ListIndex = 0 Then Exit Sub
            If List1.Selected(List1.ListIndex - 1) Then
                List1.Selected(List1.ListIndex) = False
                List1.ListIndex = List1.ListIndex - 1
            Else
                List1.Selected(List1.ListIndex) = True
                List1.Selected(List1.ListIndex - 1) = True
            End If
        End If
    End If
End Sub
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question