tags:

views:

29

answers:

1

Hi,

How I can add dynamically treeview into the combobox in wpf.. thakx..

A: 

you can do it with click event handler as given

  <TreeView Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"  MouseClick="treeview_MouseClick" ItemsSource="{Binding Children}" x:Name="Tree">

with Click event you can get the ComboBox

private void treeview_MouseClick(object sender, RoutedEventArgs e)
{
    try
    {
        TreeView treeview = sender as TreeView;
        if(treeview == null)
            return;
        var combobox = treeview .Tag as ComboBox;
        combobox .SelectedItem = treeview .SelectedItem;
    }
    catch (Exception e)
    {

    }
}
moon
this good but still I getting error ..TreeView.Tag as Combobx it will give me null value..but when i take the value as treeview and assing into the comboboxit's working, but I am not able to assing this statement... combobox .SelectedItem = treeview .SelectedItem;
Jitendra Jadav
can i see your exact code?
moon