Sending the CB_INSERTSTRING message to a combo box inserts a string into its drop-down box. The string is placed at the position specified in the parameters, regardless of whether the combo box is sorted or not.
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.
None.
Const CB_INSERTSTRING = &H14A
Const CB_ERR = -1
Const CB_ERRSPACE = -2
When the user clicks button Command1, insert three strings into combo box Combo1's drop-down box. One string is added to the beginning, one to the third position, and one to the end. To run this example, place a combo box named Combo1 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 CB_INSERTSTRING = &H14A
' *** Place the following code inside a form window. ***
Private Sub Command1_Click()
Dim retval As Long ' return value
' Add a string to the beginning of the drop-down box.
retval = SendMessage(Combo1.hWnd, CB_INSERTSTRING, ByVal CLng(0), ByVal "First Item")
' Insert a string at the third position in the drop-down box.
retval = SendMessage(Combo1.hWnd, CB_INSERTSTRING, ByVal CLng(2), ByVal "Third Item")
' Add a string to the end of the drop-down box.
retval = SendMessage(Combo1.hWnd, CB_INSERTSTRING, ByVal CLng(-1), ByVal "Last Item")
End Sub
CB_ADDSTRING, CB_DELETESTRING, CB_RESETCONTENT
Back to the Message list.
Back to the Reference section.
Last Modified: September 24, 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_insertstring.html