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 chec开发者_Go百科kBox. How can I add checkBox only for selected nodes?
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/
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.
精彩评论