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

Cance check/uncheck action?

1 Answer 44 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Arpit
Top achievements
Rank 1
Arpit asked on 09 Jul 2012, 09:26 AM
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?

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 12 Jul 2012, 06:28 AM
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 >>

Tags
TreeView
Asked by
Arpit
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or