locked
TreeView in ComboBox - how to set SelectedItem? RRS feed

  • Question

  • Hi there.

    I've embedded a TreeView in a ComboBox by customizing the ControlTemplate and substituting a TreeView instead of the ItemsPresenter. TreeView.ItemsSource is bound to ComboBox.ItemsSource so that I can display hierarchical data bound to the ComboBox.ItemsSource property.

    The problem is that I cannot do the same with the ComboBox's SelectedItem property. The behaviour I want is that the selected TreeViewItem should set the SelectedItem of the ComboBox, but I cannot find a way to do this.

    Any help appreciated.

    Andrew.
    Tuesday, September 25, 2007 4:50 PM

All replies

  • I did not try this but I guess it should work

     

    in your control template tree view bind to the selected item of the combo box

     

    <TreeView SelectedItem="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox} }, Path=SelectedItem }" >

     

    try it and let me know how it goes .... fingers crossed Smile

     

    Sunday, November 18, 2007 8:41 PM
  • You'd think it would be that easy but it seems that SelectedItem is readonly. Also SelectedItem returns a TreeViewItem rather than the object it is bound to. I've yet to figure out how to select a tree view item solely based on the object it is databound to.
    Thursday, February 21, 2008 7:56 PM
  • I have trouble with this too . This article is useful : http://www.codeproject.com/KB/WPF/WPFComboList.aspx?fid=1543229&select=3142166&fr=26#xx0xx
    Still looking for help........
    Friday, July 31, 2009 8:45 AM