CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Combobox in TreeViewItem

    Quote Originally Posted by levik View Post
    It is possible to show combobox side by side with selected TreeViewItem?
    Definitely! But in order to achieve this, you need make the combobox part of the TreeViewItem's header, instead of adding it to the child items.

    In order to display the label string and the combobox side-by-side, you need to wrap both in an appropriate panel (for example, a stack panel).

    Here's your updated XAML:
    Code:
       <TreeView Name="treeView1">
            <TreeViewItem>
                <TreeViewItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Label>aaa</Label>
                        <ComboBox Height="19">
                            <ComboBoxItem IsSelected="True">111</ComboBoxItem>
                            <ComboBoxItem>222</ComboBoxItem>
                            <ComboBoxItem>333</ComboBoxItem>
                        </ComboBox>
                    </StackPanel>
                </TreeViewItem.Header>                
                <TreeViewItem Header="aaa1">
                </TreeViewItem>                
                <TreeViewItem Header="aaa2">
                </TreeViewItem>                
            </TreeViewItem>            
            <TreeViewItem Header="bbb">
                <TreeViewItem Header="bbb1" />
                <TreeViewItem Header="bbb2" />
            </TreeViewItem>
            <TreeViewItem Header="ccc" />
        </TreeView>
    A real-world solution would rather use a ControlTemplate for applying this to all items at once - this is just to show how you can generally replace the item's header by any UIElement.
    Last edited by gstercken; April 20th, 2009 at 07:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured