LB_GETSEL Message

Platforms

Description & Usage

Sending the LB_GETSEL message to a list box checks to see if a particular item is selected.

Return Value

If the item is selected, the message returns a value greater than zero. If the item is not selected, the message returns zero. If an error occured, the message returns LB_ERR.

Visual Basic-Specific Issues

None.

Parameters

wParam
The zero-based index of the item to check the selection state of.
lParam
Not used -- set to zero.

Constant Definitions

Const LB_GETSEL = &H187
Const LB_ERR = -1

Example

Check to see if the third item of list box List1 is selected. To use this example, place a 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_GETSEL = &H187

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

Private Sub Command1_Click()
	Dim sel As Long  ' selection state of the item
	
	' Check the selection state of List1's third item.
	sel = SendMessage(List1.hWnd, LB_GETSEL, ByVal CLng(2), ByVal CLng(0))
	If sel > 0 Then
		Debug.Print "The third item is selected."
	ElseIf sel = 0 Then
		Debug.Print "The third item is not selected."
	Else
		Debug.Print "An error occured!"
	End If
End Sub

See Also

LB_GETCURSEL, LB_GETSELITEMS, LB_SETSEL

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_getsel.html