Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

API: Enabling Full Row Select in a Treeview

Author(s)
Dev Ashish

    The TreeView control which ships with ODE doesn't have a FullRowSelect property like it's VB6 cousin.  The FullRowSelect property allows you to specify if the entire row of the selected item is highlighted and clicking anywhere on an item's row causes it to be selected.

    By using SetWindowLong API function, we can specify an additional style for the TreeView control, namely TVS_FULLROWSELECT, which gives us the same functionality as FullRowSelect.

    Here are two functions to set and clear this style for a TreeView control.

'*************** Code Start *****************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
'
'Version 4.71 and later of comctl32
'Enables full-row selection in the tree view.
Private Const TVS_FULLROWSELECT = &H1000
'Retrieves the window styles.
Private Const GWL_STYLE = (-16)

Private Declare Function apiGetWindowLong Lib "user32" _
   Alias "GetWindowLongA" _
   (ByVal hWnd As Long, _
   ByVal nIndex As Long) _
   As Long
   
Private Declare Function apiSetWindowLong Lib "user32" _
   Alias "SetWindowLongA" _
   (ByVal hWnd As Long, _
   ByVal nIndex As Long, _
   ByVal dwNewLong As Long) _
   As Long

Function fTvwFullRowSelect(tvw As Control) As Boolean
   'enables full row selection for a treeview
   'The Treeview control which ships with ODE
   'already has a hWnd property, so don't need GetFocus
Dim lngStyle As Long
   
   'Retrieve the current style first
   lngStyle = apiGetWindowLong(tvw.hWnd, GWL_STYLE)
   
   'now add our style to it
   lngStyle = lngStyle Or TVS_FULLROWSELECT
   
   'finally set the new style
   fTvwFullRowSelect = (Not apiSetWindowLong(tvw.hWnd, _
                                          GWL_STYLE, lngStyle) = 0)
End Function

Function fResetTvwFullRowSelect(tvw As Control) As Boolean
   'Disables full row selection for a treeview
Dim lngStyle As Long
   
   'Retrieve the current style first
   lngStyle = apiGetWindowLong(tvw.hWnd, GWL_STYLE)
   
   'now remove our style from it
   lngStyle = lngStyle And Not TVS_FULLROWSELECT
   
   'finally set the new style
   fResetTvwFullRowSelect = (Not apiSetWindowLong(tvw.hWnd, _
                                          GWL_STYLE, lngStyle) = 0)
End Function
'*************** Code End *****************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer