TreeView scrollToKeepItemVisible

I am trying to make a modal TreeView selector. I want to scroll to a previously selected item.

Before ronModalLoop() I add the TreeViewItems and if I find a previously selected one:

if (selectedItem != 0)
	selectedItem->setSelected(true, true);

but in

void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
if (item != 0 && item->ownerView == this)

item->ownerView is valid but “this” is not?? So naturally it does not scroll.
What’s going on here?

Well it’s checking that the item you’re trying to scroll actually belongs to the treeview. I guess you’ve not yet added the item to the tree?

No, it’s allready added to the TreeView, in fact I can see at the debugger that the ownerView is correct, but the pointer “this” is shown as “0xcccccccc” (probably invalid pointer)?

Well I’d say that’s a pretty clear sign that you’re using a dangling pointer!

the TreeView is my content component, and I add items to this treeview, when I send an Item (which is already added to TreeView) to Treeview’s

void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
if (item != 0 && item->ownerView == this)

method, the “this” pointer which should show “this TreeView” (which is allready on my component and should be valid) seems to be invalid.

The confusing thing is

“item->ownerView” correctly points to this TreeView.

If ‘this’ is toasted, then obviously the pointer you’re using to call the scroll method is toast. You need to spend some quality time with your debugger.