LB_SETSEL Message

Platforms

Description & Usage

Sending the LB_SETSEL to a multiple-selection list box selects or deselects one of its items. Alternatively, the message can select or deselect all of the items simultaneously. For a single-selection list box, sned the LB_SETCURSEL message instead.

Return Value

If successful, the message returns zero. If an error occured, the message returns LB_ERR.

Visual Basic-Specific Issues

None.

Parameters

wParam
If this is zero, the item is deselected. If this is a non-zero value, the item is selected.
lParam
The zero-based index of the item to select or deselect. If this is -1, all items in the list box are selected or deselected.

Constant Definitions

Const LB_SETSEL = &H185
Const LB_ERR = -1

Example

Change the selection in list box List1 so that the only selected items are the first and third items. To use this example, place a multiple-selection 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_SETSEL = &H185

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

Private Sub Command1_Click()
	Dim retval As Long  ' return value
	
	' First, deselect all items in the list box.
	retval = SendMessage(List1.hWnd, LB_SETSEL, ByVal CLng(0), ByVal CLng(-1))
	' Then, select the first and third items.
	retval = SendMessage(List1.hWnd, LB_SETSEL, ByVal CLng(1), ByVal CLng(0))
	retval = SendMessage(List1.hWnd, LB_SETSEL, ByVal CLng(1), ByVal CLng(2))
End Sub

See Also

LB_GETSEL, LB_SETCURSEL

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