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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting items from treeview

Status
Not open for further replies.

Annelize

Programmer
Dec 17, 2004
45
GB
Good day

I was hoping somebody could shed some light on my problem. I currently
have a u_dw and a u_tvs with 2 levels. What I do is allow the user to
assign items from my datawindow to my treeview or remove them again
from the treeview.

The problem comes in when I give the user the option to remove ALL
level 2 items from the treeview. This is my code:

Code:
//remove all level 2 items from the treeview
ll_ItemHandle = tv.FindItem(RootTreeItem!, 0)

DO UNTIL ll_ItemHandle = -1

//get first child item handle
tv_default_nav.expanditem(ll_ItemHandle)
ll_childHandle = tv_default_nav.FindItem(ChildTreeItem!, ll_ItemHandle)

    DO UNTIL ll_childHandle = -1
    //Loop through all items in the child, delete(level 2)
    tv_default_nav.DeleteItem(ll_childHandle)

    ll_childHandle = tv_default_nav.FindItem(NextTreeItem!, &
       ll_childHandle)
    LOOP

ll_ItemHandle = tv_default_nav.FindItem(NextTreeItem! , ll_ItemHandle)
LOOP

My problem is the following: For some reason the

Code:
ll_childHandle = tv_default_nav.FindItem(ChildTreeItem!, ll_ItemHandle)

returns the LAST item for that level. It then removes it but as there
is no items after that, returns -1 and exits the loop. ChildTreeItem!
Is suppose to get the first child of itemhandle.

Any advice will be greatly appreciated.
Kind regards,
Annelize
 
My guess is that ll_ItemHandle is not what you expect since the FindItem method returns the next handle AFTER the specified handle.

Matt

"Nature forges everything on the anvil of time
 
Hi Matt

As far as I know ll_Itemhandle is perfect. I tested with

Group
- Item1
- Item2

and it took me to the right level. But let's say it is not correct and just by random luck it ended up at the right level. What is the mistake I'm making then? Surely to get the handle of the first level 1 item is

Code:
ll_ItemHandle = tv.FindItem(RootTreeItem!, 0)

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top