tags:

views:

97

answers:

1

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.

A: 

I used following code of line

treeview1.Items.IndexOf(treeview1.SelectedItem)

It returns -1 when we select the cild items,and it returns 1,2.etc,depends upon which parent item is get clicked.

So i used this to check whether the clciked item is child.

 if (treeview1.Items.IndexOf(treeview1.SelectedItem) == -1)
                {
                    Animal bar = (Animal)treeview1.SelectedItem;
                    string str = bar.Name;
                    int boxty = bar.BoxType;
                    int boxno = bar.BoxNo;
                }
Anu