LB_GETSELCOUNT Message

Platforms

Description & Usage

Sending the LB_GETSELCOUNT message to a multiple-selection message box counts the number of items that are selected.

Return Value

If successful, the message returns the number of items that are selected in the list box. If an error occured, the message returns LB_ERR.

Visual Basic-Specific Issues

None.

Parameters

wParam
Not used -- set to zero.
lParam
Not used -- set to zero.

Constant Definitions

Const LB_GETSELCOUNT = &H190
Const LB_ERR = -1

Example

Display a list of all items that are selected in a list box. To use this example, place a multi-select list box named List1 and a command button named Command1 on a form window.

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, _
	ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Public Const LB_GETSELCOUNT = &H190
Public Const LB_GETSELITEMS = &H191

' *** Place the following code inside the form window. ***

Private Sub Command1_Click()
	Dim items() As Long  ' indexes of the selected items
	Dim numsel As Long   ' number of selected items
	Dim c As Long        ' counter variable
	Dim retval As Long   ' return value
	
	' Count the number of selected items.
	numsel = SendMessage(List1.hWnd, LB_GETSELCOUNT, ByVal CLng(0), ByVal CLng(0))
	If numsel = 0 Then
		Debug.Print "No items are selected."
	Else
		' Resize the array so it can hold all the indexes.
		ReDim items(0 To numsel - 1) As Long
		' Get the indexes of all selected items.
		retval = SendMessage(List1.hWnd, LB_GETSELITEMS, ByVal numsel, items(0))
		' Display them.
		Debug.Print "The following items are selected (identified by index):"
		For c = 0 To numsel - 1
			Debug.Print items(c);
		Next c
		Debug.Print
	End If
End Sub

See Also

LB_GETSELITEMS

Category

List Boxes

Back to the Message list.
Back to the Reference section.


Last Modified: January 21, 2001
This page is copyright © 2001 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/l/lb_getselcount.html