I'm not sure, but I think that expanding/collapsing a treeview node generates an event, $401 (gadget) probably. Im not sure if you can tell if it just got expanded or collapsed from eventdata(), but you will probably just have to track it from each event to the next, or write a TreeViewNodeStatus(handle) userlib.
Hope it helps
Hope it helps