This is a one-line API to select or deselect all items in
a listbox.
With the controls listed below on the form, set the listbox
MultiSelect property to either Simple or Extended. Run the app, and select several items. Click the Command1 to remove the selections, or
Command2 to select all the listed items. |
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const LB_SETSEL = &H185&
Sub Form_Load()
'add this code to the form load to fill
'a list with some (15) of the system's
'screen fonts.
Dim i As Integer
Dim max As Integer
max = Screen.FontCount
If max > 15 Then max = 15
For i = 1 To max
List1.AddItem Screen.Fonts(i)
Next
Command1.Caption = "Deselect All"
Command2.Caption = "Select All"
End Sub
Private Sub Command1_Click()
Call SendMessage(List1.hwnd, LB_SETSEL, False, ByVal -1)
End Sub
Private Sub Command2_Click()
Call SendMessage(List1.hwnd, LB_SETSEL, True, ByVal -1)
End Sub |