How to change a string in a combo box
-
I have a regular combobox, and I want the selected item (the item shown in the editbox area of the combobox) to be automatically updated when I write something in another editbox. I also want this string to be "stored", so that next time I pull down the combobox this string is still there. So just manipulating the editbox itself isn't good enough. I also want the index to not change. I'm not using MFC, just plain Win32 API stuff. I hope you understand what I mean :] Sprudling :confused:
-
I have a regular combobox, and I want the selected item (the item shown in the editbox area of the combobox) to be automatically updated when I write something in another editbox. I also want this string to be "stored", so that next time I pull down the combobox this string is still there. So just manipulating the editbox itself isn't good enough. I also want the index to not change. I'm not using MFC, just plain Win32 API stuff. I hope you understand what I mean :] Sprudling :confused:
1. Get the index of the item that is in the edit area of your combo box with the CB_GETCURSEL message. 2. Remove this index from the combo box. That will remove this string completely. Use the CB_DELETESTRING message. 3. Get the text from your external edit box, probably with the WM_GETTEXT message. 4. Insert the new text string at the same index of the original string with the CB_INSERTSTRING message. One more good tip it to send a WM_SETREDRAW message with false in the WPARAM field, before you even start removing and inserting the strings in the combo box, because this will make it so that the combo box does not redraw itself while you are manipulating the data. When you are done, send a WM_SETREDRAW message with TRUE in the WPARAM field, and this will force the combo box to repaint with all of the new data.
-
1. Get the index of the item that is in the edit area of your combo box with the CB_GETCURSEL message. 2. Remove this index from the combo box. That will remove this string completely. Use the CB_DELETESTRING message. 3. Get the text from your external edit box, probably with the WM_GETTEXT message. 4. Insert the new text string at the same index of the original string with the CB_INSERTSTRING message. One more good tip it to send a WM_SETREDRAW message with false in the WPARAM field, before you even start removing and inserting the strings in the combo box, because this will make it so that the combo box does not redraw itself while you are manipulating the data. When you are done, send a WM_SETREDRAW message with TRUE in the WPARAM field, and this will force the combo box to repaint with all of the new data.