LB_SETCURSEL Message

Platforms

Description & Usage

Sending the LB_SETCURSEL message to a single-selection list box sets the item that is currently selected, or clears the selection entirely. For multiple-selection list boxes, send the LB_SETSEL message instead.

Return Value

If successful, the message returns 1. If an error occured, or if the selection was cleared, the message returns LB_ERR.

Visual Basic-Specific Issues

None.

Parameters

wParam
The zero-based index of the item to select. To clear the selection, set this to -1.
lParam
Not used -- set to zero.

Constant Definitions

Const LB_SETCURSEL = &H186
Const LB_ERR = -1

Example

Select the second item in list box List1. To use this example, place a single-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_SETCURSEL = &H186

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

Private Sub Command1_Click()
	Dim retval As Long  ' return value
	
	' Change the selection in list box List1 to the second item.
	retval = SendMessage(List1.hWnd, LB_SETCURSEL, ByVal CLng(1), ByVal CLng(0))
End Sub

See Also

LB_GETCURSEL, 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_setcursel.html