Jump to content
Tuts 4 You
Sign in to follow this  
CodeExplorer

Remove listbox content Visual C++ ???

Recommended Posts

CodeExplorer

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

 

Share this post


Link to post
Share on other sites
atom0s

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.

Share this post


Link to post
Share on other sites
CodeExplorer

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

Share this post


Link to post
Share on other sites
CodeExplorer

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

 

Share this post


Link to post
Share on other sites
atom0s

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

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×