How to select checked treeview item?

3 posts, 0 answers
  1. Ruth
    Ruth avatar
    16 posts
    Member since:
    Nov 2011

    Posted 22 Feb 2012 Link to this post

    If I click on a checkbox, it does not select a treeview item. How to programmatically select it?
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 23 Feb 2012 Link to this post

    Hi Ruth,

    Thank you for contacting us. You can use the Checked and Unchecked events of RadTreeView:

    <telerik:RadTreeView IsTriStateMode="True" IsOptionElementsEnabled="True" ItemsOptionListType="CheckList"
            Checked="RadTreeView_Checked" SelectionMode="Multiple" Unchecked="RadTreeView_Unchecked">
        <telerik:RadTreeViewItem Header="Root">
            <telerik:RadTreeViewItem Header="Child #1" />
            <telerik:RadTreeViewItem Header="Child #2" />
            <telerik:RadTreeViewItem Header="Child #3" />
        </telerik:RadTreeViewItem>
    </telerik:RadTreeView>

    private void RadTreeView_Checked(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        RadTreeViewItem checkedItem = e.OriginalSource as RadTreeViewItem;
        if (checkedItem != null)
        {
            checkedItem.IsSelected = true;
        }
    }
     
    private void RadTreeView_Unchecked(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        RadTreeViewItem checkedItem = e.OriginalSource as RadTreeViewItem;
        if (checkedItem != null)
        {
            checkedItem.IsSelected = false;
        }
    }

    Give it a try and let me know if it works. I'd be glad to further assist you.

    Greetings,
    Kiril Stanoev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Ruth
    Ruth avatar
    16 posts
    Member since:
    Nov 2011

    Posted 28 Feb 2012 Link to this post

    Works great, thank you!
Back to Top