DirList Single Click

Author: Dave
Date: 07.08.16 - 2:27am

Its pretty rare than I use the VB6 dirlist control. It feels a bit old but it is easy to use. This morning I am creating a replacement for the Windows BrowseFolder dialog and using the default VB directory list control as part of it.

One behavior that I dont really care for in it is that it requires you to double click on a folder in order to select it. I find myself selecting the wrong directory on occasion because it looks selected in the control, yet it is not really the actively selected directory.

The question: is there an easy way to have the control auto select the folder you click on with a single click instead of a double click without subclassing?

Answer: yes its easy

Private Declare Sub mouse_event Lib "user32" ( _
						ByVal dwFlags As Long, _
						ByVal dX As Long, _
						ByVal dY As Long, _
						ByVal cButtons As Long, _
						ByVal dwExtraInfo As Long)
Private Const LEFTDOWN = &H2, LEFTUP = &H4
Private ignoreAutomation As Boolean

Private Sub Dir1_Click()
    If ignoreAutomation Then
        ignoreAutomation = False
        ignoreAutomation = True
        mouse_event LEFTDOWN, 0&, 0&, 0&, 0&
        mouse_event LEFTUP, 0&, 0&, 0&, 0&
        mouse_event LEFTDOWN, 0&, 0&, 0&, 0&
        mouse_event LEFTUP, 0&, 0&, 0&, 0&
    End If
End Sub

Comments: (3)

On 08.21.16 - 12:20pm Aurel Cortez wrote:
This works but if there is a subdirectory underneath the main folder it highlights the that subdir but the content of the filelistbox is the that of the main folder.

On 08.22.16 - 6:47am Dave wrote:
Hi, thanks for the bug report. I did not notice this behavior. To fix this visual display bug I had to work a little winapi voodoo. The fix can be found at the following link:


The bug was visible if you clicked on a sub directory that itself had many sub directories. If the list was long enough to still have an entry under the current mouse position (which does not move when the list compacts and re-expands), then whatever entry that was currently under the mouse would be visually highlighted in the control, even though that was not the one set in teh dir1.path property.

This control is a little low rent in its behavior but I think I ironed it out.

On 08.28.16 - 7:55am Aurel Cortez wrote:
I must say its a huge undertaking that involves WinAPI, PointAPI, Rect Structs for a very small feature. ) But it works great though. Thanks for the effort.

Leave Comment:
Email: (not shown)
Message: (Required)
Math Question: 15 + 93 = ? followed by the letter: Y 

About Me
More Blogs
Main Site
Console tricks
FireFox temp dir
OCX License
Extract substring
VB6 Console Apps
VB6 Debugger View As Hex tooltips
VB6 - C Share registry data
VB6 Addin Missing Menus
VB6 Class Init Params
VB6 isIn function
Python and VB6
Python pros and cons
download web Dir
vc rand in python
VB6 Language Enhancement
Register .NET as COM
UDT Tricks pt2
Remote Data Extraction
Collection Extender
VB6 FindResource
DirList Single Click
Reset CheckPoint VPN Policy
VB6 BSTR Oddities Explained
SafeArrays in C
BSTR and Variant in C++
Property let optional args
Misc Libs
Enum Named Pipes
Vb6 Collection in C++
VB6 Overloaded Methods
VB6 Syncronous Socket
Simple IPC
VB6 Auto Resize Form Elements
Mach3 Automation
Exit For in While
C# self register ocx
VB6 Class Method Pointers
JS Debugger
Duktape Debug Protocol
QtScript 4 VB
Vb6 Named Args
vb6 Addin Part 2
VB6 Addin vrs Toolbars
OpenFile Dialog MultiSelect
Duktape Example
DukTape JS
VB6 Unsigned
.Net version
TitleBar Height
.NET again
VB6 Self Register OCXs
Query Last 12 Mos
Progid from Interface ID
VB6 to C Array Examples
Human Readable Variant Type
ScriptBasic COM Integration
CodeView Addin
ScriptBasic - Part 2
Script Env
printf override
History Combo
Disable IE
API Hooking in VB6
Addin Hook Events
FastBuild Addin
VB6 MemoryWindow
Link C Obj Files into VB6
Vb6 Standard Dlls
CStr for Pascal
Lazarus Review
asprintf for VS
VB6 GlobalMultiUse
Scintilla in VB6
Dynamic Highlight
WinVerifyTrust, CryptMsgGetParam VB6
MS GLEE Graphing
printf for VB6
C# App Config
Tero DES C# Test
VC 2008 Bit Fields
Speed trap
C# Db Class Generator
VB6 vrs .NET (again)
FireFox Whois Extension
git and vb6
Code Additions
Compiled date to string
C# ListView Sorter
VB6 Wish List
C# Process Injection
C# PE Offset Calculator
VB6 Async Download
Show Desktop
coding philosophy
Code release
Dll Not Found in IDE
Advanced MSScript Control
random tip
Clipart / Vector Art
VB6 Callback from C#
Binary data from VB6 to C#
CSharp and MsScriptControl
HexDumper functions
Js Beautify From VB6 or C#
vb6 FormPos
Inline Asm w VB6
The .NET Fiasco
One rub on computers
Universal extractor