This is a migrated thread and some comments may be shown as answers.

Binding to Checkbox on Treeview Item

7 Answers 157 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jarred Froman
Top achievements
Rank 1
Jarred Froman asked on 11 Sep 2008, 04:18 PM
I would like to bind to the checkbox on the Treeview using Templates and databinding.  Does anybody know of a way to do this?

Thanks,
-Jarred Froman

7 Answers, 1 is accepted

Sort by
0
Jonathan Miller
Top achievements
Rank 1
answered on 12 Sep 2008, 02:28 PM
Hi Jarred, how do you want to bind the data?  From WCF database?
0
Valentin.Stoychev
Telerik team
answered on 15 Sep 2008, 10:45 AM
Hello Jarred,

There are several events exposed from the checkbox/radio buttons in the RadTreeView - Checked, PreviewChecked. There is also CheckState property for the RadTreeViewItem that you can use. 

What is the scenario? If using the existing mechanism is not extensible enough - what will make your life easier?

All the best,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jarred Froman
Top achievements
Rank 1
answered on 15 Sep 2008, 02:29 PM
Given the following code:


<UserControl.Resources>
    <DataTemplate x:Key="CountryTemplate">
        
<TextBlock Text="{Binding Name, Mode
=OneWay}" />
    
</DataTemplate>

    <DataTemplate x:Key="RegionTemplate">
        
<TextBlock Text="{Binding Region, Mode=OneWay}" />
    
</DataTemplate>

    
<Telerik:HierarchicalDataTemplate x:Key="Region"
                            HeaderTemplate="{StaticResource RegionTemplate}"
                            
ItemsSource = "{Binding Countries.Items, Mode=OneWay}"
                            
ItemTemplate="{StaticResource CountryTemplate}" />

</UserControl.Resources>

<Client:GodotTreeView x:Name="trvSelectedCountries" IsEditable="False" 
                ItemsSource
="{Binding Regions, Mode=OneWay}" 
                ItemTemplate
="{StaticResource Region}" />



We would like to databind on the checkstate of each individual item without having to rely on events.  Currently, the way we got around this is by not using the checkbox functionality already in the treeview and just using a CheckBox inside the datatemplate, however, we would prefer to work off the existing treeview functionality if possible.

Thanks,
-Jarred Froman
0
Jarred Froman
Top achievements
Rank 1
answered on 15 Sep 2008, 02:29 PM
Given the following code:


<UserControl.Resources>
    <DataTemplate x:Key="RegionTemplate">
        
<TextBlock Text="{Binding Region, Mode=OneWay}" />
    
</DataTemplate>

    
<Telerik:HierarchicalDataTemplate x:Key="Region"
                            HeaderTemplate="{StaticResource RegionTemplate}"
                            
ItemsSource = "{Binding Countries.Items, Mode=OneWay}"
                            
ItemTemplate="{StaticResource CountryTemplate}" />

</UserControl.Resources>

<Client:GodotTreeView x:Name="trvSelectedCountries" IsEditable="False" 
                ItemsSource
="{Binding Regions, Mode=OneWay}" 
                ItemTemplate
="{StaticResource Region}" />



We would like to databind on the checkstate of each individual item without having to rely on events.  Currently, the way we got around this is by not using the checkbox functionality already in the treeview and just using a CheckBox inside the datatemplate, however, we would prefer to work off the existing treeview functionality if possible.

Thanks,
-Jarred Froman
0
Valentin.Stoychev
Telerik team
answered on 17 Sep 2008, 08:32 AM
Hello Jarred Froman,

For this purpose you can use the CheckState property of the RadTreeViewItem?

Best wishes,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jarred Froman
Top achievements
Rank 1
answered on 17 Sep 2008, 01:36 PM
Given the code above, how would I databind to that?

Thanks,
-Jarred Froman
0
Valentin.Stoychev
Telerik team
answered on 18 Sep 2008, 04:24 PM
Hello Jarred,

My bad - this is not curently supported in Silverlight - it is possible in WPF at the moment :(. So the only option for the moment is by using TreeViewItem events or the way you did it.

Sorry once again for misleading you - let us know if we can help you further with your scenario.

Greetings,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Jarred Froman
Top achievements
Rank 1
Answers by
Jonathan Miller
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Jarred Froman
Top achievements
Rank 1
Share this question
or