none
WPF Treeview menu RRS feed

  • Question

  • Hi,

       <TreeView Height="455" HorizontalAlignment="Left" Name="TreeView1"  VerticalAlignment="Top" Width="223" Margin="7,8,0,0" SelectedItemChanged="TreeView1_SelectedItemChanged">
                    <TreeViewItem Name="first" Header="Tables" ItemTemplate="{StaticResource itemsTemplate}">
                    </TreeViewItem>
                    <TreeViewItem Header="Blobs" Name="blob" ItemTemplate="{StaticResource itemsTemplate}"></TreeViewItem>
                    <TreeViewItem Header="Queue" Name="Queue" ItemTemplate="{StaticResource itemsTemplate}"></TreeViewItem>
                </TreeView>

    How to get the selected value on selecteditemchanged>

    Thanks

    Pritish

    Monday, May 2, 2011 4:44 AM

Answers

  • Hi,

    Write this way.

     private void TreeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)

            {

                TreeViewItem item = TreeView1.SelectedItem as TreeViewItem;

                MessageBox.Show(item.ToString());

            }

     

    Thanks,

    Rajnikant

     

    Monday, May 2, 2011 5:44 AM

All replies

  • Hi,

    Write this way.

     private void TreeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)

            {

                TreeViewItem item = TreeView1.SelectedItem as TreeViewItem;

                MessageBox.Show(item.ToString());

            }

     

    Thanks,

    Rajnikant

     

    Monday, May 2, 2011 5:44 AM
  • Hi,

    I am marking this issue as "Answered". If you have any new questions or concerns about this issue, please feel free to let me know.

    Thank you and have a nice day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 5, 2011 7:24 AM
    Moderator