Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CTreeView Problem

Status
Not open for further replies.

streamt

Programmer
Feb 18, 2004
3
RO
I get an error when tryng to clear the list.
When I call:
GetTreeCtrl().DeleteAllItems();
I get a debug assertion error.
I'd appreciate if you could help me.
 
Assume you have CMainFrame window class and the view associated with is a CTreeView let say CTek04View.
The following code is working :
CMainFrame * pFrame = (CMainFrame *) AfxGetMainWnd();
if (pFrame)
{
CTek04View * pView = (CTek04View *) pFrame->GetActiveView();
if (pView)
{
pView->GetTreeCtrl().DeleteAllItems();
}
else
{
// error no view object with this Frame window
}
}
else
{
// error no Frame window !
}
-obislavu-
 
I'm sorry. It was my fault I didn't gave details. My code is exactly like the one you gave me.
The thing is that I don't always get an error. When I open a new document or an old one I try to delete all the items in the list. If the last item is selected, the list is cleared and nothing happens. But if any other item but the last one is selected, I get an assertion error. It's very confusing. I thought that it has something to do with the item's handle (HTREEITEM), but I'm not sure.
 
If you have a pointer to the control and it is not null then DeleteAllItems() should work even there are no items in the tree or they are selected or not.
Put more code here.
-obislavu-
 
I was using the DeleteAllItems() function in OnNewDocumnent() and in OnOpenDocument() and it didn't work. Now I've moved it into DeleteContents() and is working perfectly. Can you explain me why is that? It seemed to be more logically that the function would be in OnNewDocumnent() and OnOpenDocument(),because it's an initialization of a view.
 
>It seemed to be more logically that the function would be in ... because it's an initialization of a view

Most logical place for that would be the view's OnInitialUpdate.

The whole idea of the doc-view concept is that the doc shouldn't deal with view-specific layout thingies (such as a CTreeCtrl).

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top