0

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?

nirmus
  • 4,913
  • 9
  • 31
  • 50
  • possible duplicate http://stackoverflow.com/questions/698369/how-to-disable-a-winforms-treeview-node-checkbox – Renatas M. Aug 31 '11 at 07:59

2 Answers2

1

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/

Ezekiel Rage
  • 541
  • 6
  • 14
0

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.

AkselK
  • 2,563
  • 21
  • 39