Making Enter Key in Directory List Box Act Like Double-Click

Last reviewed: June 21, 1995
Article ID: Q93215
The information in this article applies to:
  • Microsoft Visual Basic for Windows, versions 1.0, 2.0, and 3.0
  • The Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0

SUMMARY

When you double-click an item in a directory list box control, it opens the directory and displays its subdirectories.

The directory list box control ignores the Enter key by default. To cause a directory list box to treat the Enter key the same way as a double-click, set the Path property to List(ListIndex) from within the KeyPress event handler.

MORE INFORMATION

The following code shows how to cause a directory list box to open the selected directory when the user presses the ENTER key. This code causes a Change event, just as when you double-click an item.

   Sub Dir1_KeyPress (KeyAscii As Integer)
      If KeyAscii = 13 Then
         Dir1.Path = Dir1.List(Dir1.ListIndex)
      End If
   End Sub

If your form contains a command button with the Default property set to True, pressing the ENTER key clicks the command button instead of firing the KeyPress event. In this case, set the Path property to List(ListIndex) from within the button Click event handler. For example:

   Sub Command1_Click ()
      Dir1.Path = Dir1.List(Dir1.ListIndex)
   End Sub

Additional reference(s):

Chapter 18, "Using the File-System Controls" of the "Microsoft Visual Basic for Windows Programmer's Guide"

Chapter 10, "Using the File-System Controls" of the "Microsoft Visual Basic for MS-DOS Programmer's Guide"


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.