Temp
Temp

Reputation: 109

How to pick a specific treenode expanded in C#

I am showing data in db by treeview. Every data has its own code and parent code (not a level). My showing algorithm step is like this

node1

└ node2     - click expand icon

  └ node3 

└ node4     - selected node

In this case, I can only check selected node(node4). So If I put a adding child node code in event click or expand/collapse, code is working on selected node(node 4), not a node 2.

This is why I using click event.

I want to check which node`s expand icon was clicked. In this example, what node i want to get is node2.

A ignorant but simple way is well... save all of node's status and compare before expanded with after. This way will take too long when number of nodes is large.

If there is other simple way to pick a node2, I want to know how I can find it.

Sorry for my poor explanation.

Upvotes: 0

Views: 668

Answers (1)

Dirk Trilsbeek
Dirk Trilsbeek

Reputation: 6033

You can use the OnBeforeExpand event of the treeview. The event has a TreeViewCancelEventArgs argument that carries the node to be expanded in its Node property.

Upvotes: 2

Related Questions