I'm building a windows application, and I have this combobox refusing to get clean. I want the combo box items to be deleted between one button click to another. I tried :
SendDlgItemMessage(hWnd, IDC_LIST_COMMANDS, CB_RESETCONTENT, 0, 0);
and also:
SendMessage(CommandsListBox, CB_RESETCONTENT, 0, 0);
but none of them work. I dont get 0 when I call LB_GETCOUNT after one of the above calls.
case SOME_EVENT:
ProfileHandler.IdentityIndex = (int)SendMessage(ProfilesCombo,
CB_GETCURSEL, 0, 0);
SendMessage(ProfilesCombo, CB_GETLBTEXT,
(WPARAM)ProfileHandler.stringIndex, (LPARAM)ProfileHandler.string);
if (ProfileHandler.IdentityIndex == -1) {
MessageBox(hWnd, "Invalid !", "Error !", MB_OK);
break;
}
StringsSet.clear();
if (fuc.GetStrings(string(ProfileHandler.string), &StringsSet)
== SERVER_ERROR) {
MessageBox(hWnd, "Error Loading strings", "Error !", MB_OK);
break;
}
SendMessage(CommandsListBox, CB_RESETCONTENT, 0, 0); // reset
content before writing strings
it = StringsSet.begin();
for (; it != StringsSet.end(); ++it)
{
(int)SendMessage(CommandsListBox, LB_ADDSTRING, 0,
(LPARAM)(*it).c_str());
}
break;
so, I between every SOME_EVENT received by click, I want to clear the combobox, and load the string again. right now what's happenning is that every time I click the button, and the SOME_EVENT event received, I just load the commands all over again, causing a duplication . any idea how to solve this??
I just wrote code that resets all items into a ComboBox. The correct way is to use: SendMessage(hcombobox, CB_RESETCONTENT, 0, 0); I write this because the problem was that the user that started this thread was using a ListView and not a ComboBox. Jonathan Potter solved this issue. I've written this to give visibility to the correct answer. Forgive my mistakes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With