How to get parent item in Treeview
Posted
by Anu
on Stack Overflow
See other posts from Stack Overflow
or by Anu
Published on 2010-04-20T09:22:55Z
Indexed on
2010/04/20
9:23 UTC
Read the original article
Hit count: 315
Hi,To get the child items as string i used the following code
private void treeview1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (treeview1.SelectedItem != null)
{
Animal bar = (Animal)treeview1.SelectedItem;
string str = bar.Name;
int boxty = bar.BoxType;
int boxno = bar.BoxNo;
}
}
It works fine .But when i click on parent(instead of + sign),it goes to this code and shows error.Ofcourse im casting SelectedItem to my List-Animal. But i dont want this.I have to check,whether the clciked item is parent,if it is so then i will skip this coding.Only when i click the child items it will go to this coding. How can i do that?How can i identify the selected item is parent.
© Stack Overflow or respective owner