Cance check/uncheck action?

2 posts, 0 answers
  1. Arpit
    Arpit avatar
    5 posts
    Member since:
    Jun 2011

    Posted 09 Jul 2012 Link to this post

    Here is what I am trying to achieve with tristate TreeView:

    1. User unchecks an item from tree
    2. Before the item gets really unchecked from tree, I need to put a validation
    3. If item passes this validation, it should be unchecked. Else the uncheck event needs to be canceled and item should remain checked.

    I tried setting e.Handled in PreviewUnchecked which is not working. The item gets already unchecked.

    Any ideas how this can be achieved?
  2. Petar Mladenov
    Petar Mladenov avatar
    2991 posts

    Posted 12 Jul 2012 Link to this post

    Hello Arpit,

     If you need your validation on uncheck to work only for the item you have tried to uncheck with your mouse, you have to use the IsUserItnitiated property like so:

    private void treeView_PreviewUnchecked(object sender, Telerik.Windows.RadRoutedEventArgs e)
            bool isInitiallyChecked = (e as RadTreeViewCheckEventArgs).IsUserInitiated;
            if (isInitiallyChecked && ((e.OriginalSource as RadTreeViewItem).DataContext as DataItem).Name.Contains("0"))
                e.Handled = true;
    You can find this realized in the attached sample. Please let us know if this helps you or not. Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top