Can someone please tell me what is the event that is triggered when a user clicks on the + sign in C# TreeView?

To elaborate more, here is my problem.

I have a tree view that is populated at the time of Form_Load. Then the user can expand/collapse/select etc with it. However, from time to time, the tree view might get data from a service, and once it does and the nodes are changed it will automatically update with new data. This update function is such that it populates the whole tree view from the beginning - simply it calls the methods that is called at Form_Load.

My requirement is, let's say I had a certain portion of the Tree expanded by clicking on the little + icon. (Note that I haven't SELECTED any nodes, just clicked on the little icon only. Thus I cannot use the SelectedNode property.) So imagine while I have a certain part of the Tree expanded, some new data comes in and the TreeView is drawn again. Now, I want the TreeView to display the previously selected portion again after it finished it's updating.

How can I do it?

In the case the user had actually selected a node, I can remember it before updating and then user Node.EnsureVisible() to go back to the selection. Wonder how I can achieve it when the user has only clicked on the little + icon.

Recommended Answers

All 2 Replies

Wouldn't that be the BeforeExpand/BeforeColapse events (along with the AfterExpand/AfterColapse).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.