devxlogo

Set the Text of the Edit Control Portion of a ComboBox

Set the Text of the Edit Control Portion of a ComboBox

The following is a way to programatically set the text in the combo box without adding to the list box portion.
When using a combo box, if the style is CBS_DROPDOWN, users can enter any text in the edit box portion of it. There is no direct way of adding text to a combo box’s edit control without adding it to the listbox as well. Programmers usually insert the required text to the list box of the combo box and then select the text to achieve the desired result.
Because this method may be unacceptable in certain cases, the following method is useful.
Assume hCombo is the window handle of the combo box.

 POINT point;point.x = 1;point.y = 1;HWND hEdit = ChildWindowFromPoint(hCombo, point);SetWindowText(hEdit,"Hello World");
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist