Binding to Checkbox on Treeview Item

8 posts, 0 answers
  1. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 11 Sep 2008 Link to this post

    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
  2. Jonathan Miller
    Jonathan Miller avatar
    57 posts
    Member since:
    Jun 2008

    Posted 12 Sep 2008 Link to this post

    Hi Jarred, how do you want to bind the data?  From WCF database?
  3. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 15 Sep 2008 Link to this post

    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.
  4. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 15 Sep 2008 Link to this post

    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
  5. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 15 Sep 2008 Link to this post

    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
  6. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 17 Sep 2008 Link to this post

    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.
  7. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 17 Sep 2008 Link to this post

    Given the code above, how would I databind to that?

    Thanks,
    -Jarred Froman
  8. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 18 Sep 2008 Link to this post

    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.
Back to Top