Trap Error on SelectedItem change

3 posts, 0 answers
  1. Joel Palmer
    Joel Palmer avatar
    175 posts
    Member since:
    May 2009

    Posted 29 Jun 2015 Link to this post

    I have the SelectedItem of my TreeListView bound to a property.  However, if conditions aren't met that Property will throw an exception.  How do I capture that exception?  Is it a Binding error?  Is it a Data error?  How do I trap and expose it?  DataError and GiveFeedback events don't seem to give me anything to trap.


        IsReadOnly="{Binding IsReadOnly}"
        ItemsSource="{Binding Hierarchy, Mode=TwoWay}"
        SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
        IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}" DataError="treeListView_DataError" GiveFeedback="treeListView_GiveFeedback">
                ItemsSource="{Binding Children}"/>
                DataMemberBinding="{Binding Name, Mode=TwoWay}"
                CellTemplate="{StaticResource TreeNodeTemplate}"
                Header="Item Type"
                DataMemberBinding="{Binding ItemTypeID, Mode=TwoWay}"
                ItemsSource="{Binding TypeModel.Items, Mode=TwoWay}"
                DataMemberBinding="{Binding IsActive, Mode=TwoWay}"

  2. Joel Palmer
    Joel Palmer avatar
    175 posts
    Member since:
    May 2009

    Posted 29 Jun 2015 Link to this post

    To provide more context, I have a MainWindow --> UserControl --> TreeListView.  The MainWindow has a ModelView DataContext that has several sub-ModelViews.  So, the DataContext glues multiple UserControls together. 
    When I select an item on the TreeListView control, the Property fires a "PropertyValueChanging" event where I perform a Save on another control in the UI.  Then, the property value is updated and I fire a "PropertyValueChanged" event where I then perform a Load on another control in the UI.

    Problem is, if an exception is thrown in the PropertyValueChanging event handler, I want to expose the exception to the user and I want the TreeListView to stay on the "old" item; not the just-clicked item.  I have figured out how to expose the error to the user but I don't know how to prevent the TreeListView from moving to the newly selected node.

  3. Ivan Ivanov
    Ivan Ivanov avatar
    1201 posts

    Posted 02 Jul 2015 Link to this post


    As far as I can understand, you perform the validation logic in the ViewModel. So that, RadTreeListView's SelectedItem property is updated first and then the bound property may throw an exception. Thus you need to process the exception and set the valid value to the SelectedItem property manually. Is it possible for you to carry out this validation in RadTreeListView's SelectionChaning event, so that you can prevent the SelectedItem property from changing its value if it is an invalid one?

    Ivan Ivanov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top