I am not able to get , only the current item which is expanded . When I am trying to get the expanded item , i am getting all the expanded items from the treeview, but I don't want that , I need to get the clicked expanded item.
Asked
Active
Viewed 2,158 times
1
-
By `clicked expanded item`, do you mean the currently selected item? If so, see http://stackoverflow.com/q/1238304/464709. – Frédéric Hamidi Nov 01 '11 at 07:32
-
How can you be sure of **current** expanded item? Coz you can expand more than one tree view items, correct? I guess what you want is current selected item. Correct me if I am wrong. – WPF-it Nov 01 '11 at 07:36
-
In a treeview u are right ,there can be many items expanded . The problem which i am facing is i need only the Item which i expanded when I click on perticular item . Suppose in treeview I click on a root element for example School . Under school we have a "class" as its child , then we have "student" as "Class" item's child.So I need is "School" when I expand school , and "Class" when I expand class, and "Student" when I expand student . But here when I expand Student with treeviewitem.expand event, I am getting School and Class both because both are expanded when I expand Class . – user979901 Nov 01 '11 at 10:07
-
I have tries this approach earlier , but in my case case if we do it ,the child node does not appear – user979901 Nov 01 '11 at 12:04
2 Answers
2
You'll need to respond to the AfterExpand event.
By restricting to the click you are shutting out keyboard users.
EDIT
Sorry, that's WinForms. Here is the WPF solution:
<TreeView TreeViewItem.Expanded="TreeViewItem_Expanded" />

Emond
- 50,210
- 11
- 84
- 115
2
Please use
e.Handled=true;
in your treeViewItem.Expanded
event handler. That way it will only fire for the actual item expanded and not bubble route to the parent tree view items.

WPF-it
- 19,625
- 8
- 55
- 71