TreeNode collapse method does not persist the state of the sub-nodes

A

amidanr

Hi all,

I haven't been able to find any post regarding this problem...
the MSDN help about TreeNode.Collapse clearly says:

"The state of a TreeNode is persisted. For example, if the next level
of child nodes was not collapsed previously, when the Expand method is
called, the child nodes appear in their previously expanded state."

but what actually happens, is that all the sub node are collapsed as
well...is that the normal behaviour? how can I persist their state?

Thanks,
Amidan.
 
T

Tom Dacon

This works just like the documentation for me, on vs2003, with framework
1.1.4322 SP1.

I'd check to see if you have any code in the treeview's BeforeCollapse,
BeforeExpand, AfterCollapse, or AfterExpand event handlers that might be
affecting what's going on.

HTH,
Tom Dacon
Dacon Software Consulting
 
C

Claes Bergefall

To have it work according to the docs you'll need to use
P/Invoke and send a TVM_EXPAND message to it
That will persist the state of the subnodes

Public Declare Auto Function SendMessage Lib "User32.dll" (ByVal hwnd As
IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As
IntPtr) As Integer
Public Const TV_FIRST As Integer = &H1100
Public Const TVM_EXPAND As Integer = TV_FIRST + 2
Public Const TVE_COLLAPSE As Integer = &H1
Public Const TVE_EXPAND As Integer = &H2
Public Const TVE_TOGGLE As Integer = &H3

.....
SendMessage(myTreeView.Handle, TVM_EXPAND, TVE_COLLAPSE, myTreeNode.Handle)

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top