nirmus
nirmus

Reputation: 5093

treeView with checkBoxes for selected nodes

I'm working with application, which use TreeView. I want some nodes have checkBoxes, but not all. I know that I can do:

    treeView.CheckBoxes = true;

But then all nodes have checkBox. How can I add checkBox only for selected nodes?

Upvotes: 0

Views: 2668

Answers (2)

AkselK
AkselK

Reputation: 2593

You need to make a new template for your treeviewitem, or your dataitems.

Something like this:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <CheckBox Grid.Column="0" x:Name="checkBox" Visibility="Hidden"/>
    <ContentPresenter Grid.Column="1"/>
</Grid>
<ControlTemplate.Triggers>
    <Trigger Property="IsSelected" Value="True">
        <Setter TargetName="checkBox" Property="Visibility" Value="Visible"/>
    </Trigger>
</ControlTemplate.Triggers>

edit: Obviously, this is for WPF. If you are using WinForms, then this will not be of any help. Sorry.

Upvotes: 0

Ezekiel Rage
Ezekiel Rage

Reputation: 581

Looking at the TreeNode class it seems you'll have to implement a custom OnDrawNode function and perform some Tag manipulation.

An example: http://social.msdn.microsoft.com/forums/en-US/winforms/thread/9fbc737b-8385-4285-aa80-0e4602ff5b9b/

Upvotes: 1

Related Questions