Posted June 16, 20187 yr Remove listbox content Visual C++ ??? I wanna remove all items from listbox, Already tried ResetContent but it doesn't work: CWnd *pWnd = GetDlgItem(IDC_LIST1); CListBox* listbox = static_cast<CListBox*>(pWnd); //dynamic_cast does not work listbox->ResetContent();
June 16, 20187 yr If you are using MFC you don't use GetDlgItem API, you use the parent dialog as the owner to get its child with its sub-call for GetDlgItem, such as: CListBox* pListBox = pDialog->GetDlgItem(IDC_LIST1); Where pDialog is the pointer to your dialog object.
June 17, 20187 yr Author @atom0s: GetDlgItem returns 'class CWnd *' or HWND and not CListBox*, so your code is wrong and won't work. The first part code works ok, the listbox->ResetContent(); is the one which doesn't make what I want!
June 17, 20187 yr Author Found a solution, is not very elegant but it works: CWnd *pWnd = GetDlgItem(IDC_LIST1); CListCtrl* clist = static_cast<CListCtrl*>(pWnd); // CListCtrl* clist = (CListCtrl*)(pWnd); int numOfItems = clist->GetItemCount(); for (int i = numOfItems - 1; i >= 0; i--) clist->DeleteItem(i);
Create an account or sign in to comment