CB_ADDSTRING Message

Platforms

Description & Usage

Sending the CB_ADDSTRING message to a combo box control adds a string to the control's drop-down list. If the combo box is sorted, the new string is added in its proper position according to the sort. If the combo box is not sorted, the new string is added to the end. To control where the string is added, use the CB_INSERTSTRING message instead.

Return Value

If successful, the message returns the zero-based index of the newly added string's position in the combo box's drop-down box. If there is insufficient space to store the new string, the message returns CB_ERRSTRING. If some other error occurs, the message returns CB_ERR.

Visual Basic-Specific Issues

None.

Parameters

wParam
Not used -- set to 0.
lParam
The string to add to the combo box's drop-down box.

Constant Definitions

Const CB_ADDSTRING = &H143
Const CB_ERR = -1
Const CB_ERRSPACE = -2

Example

When the user clicks button Command1, empty the drop-down box of combo box Combo1, and then add three strings to it. The order in which the strings appear will depend on whether the combo box is sorted or not.

To use this example, place a combo box named Combo1 and a command button named Command1 on a form window. To verify that the combo box's list is being emptied, you may wish to add some items to it before running the example.

' 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 CB_ADDSTRING = &H143
Public Const CB_RESETCONTENT = &H14B

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

Private Sub Command1_Click()
	Dim retval As Long  ' return value
	
	' Empty the drop-down box of Combo1.
	retval = SendMessage(Combo1.hWnd, CB_RESETCONTENT, ByVal CLng(0), ByVal CLng(0))
	
	' Now add three strings to Combo1.  Their exact placement will
	' depend on whether Combo1 is sorted or not.
	retval = SendMessage(Combo1.hWnd, CB_ADDSTRING, ByVal CLng(0), ByVal "First Item Added")
	retval = SendMessage(Combo1.hWnd, CB_ADDSTRING, ByVal CLng(0), ByVal "Second Item Added")
	retval = SendMessage(Combo1.hWnd, CB_ADDSTRING, ByVal CLng(0), ByVal "Last Item Added")
End Sub

See Also

CB_DELETESTRING, CB_INSERTSTRING, CB_RESETCONTENT

Category

Combo Boxes

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


Last Modified: Month DD, 2000
This page is copyright © 2000 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/c/cb_addstring.html