Jump to content
Tuts 4 You

Remove listbox content Visual C++ ???


CodeExplorer

Recommended Posts

CodeExplorer
Posted

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();

 

Posted

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.

CodeExplorer
Posted

@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!
 

CodeExplorer
Posted

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);

 

Posted

You're not using GetDlgItem the way I mentioned which is why you think its wrong.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...