How to cancel the Current Item Changed event

3 posts, 0 answers
  1. Marcelo
    Marcelo avatar
    40 posts
    Member since:
    Jul 2011

    Posted 09 Nov 2011 Link to this post

    There are times when I would need to cancel the Current Item Changed event. This is based on un-saved data for exmaple. So, when the user clicks on the right/left arrows (for navigation), the Data Form instantly changes the Current Item and then fires the event.

    Well, if conditions determine that the user should not move forward/backward, how do I go back to the previous Current Item?

    Example: Data Form has three values (1, 2, 3). Current Item is 2. User clicks right nav. arrow and Data Form takes the user to Item 3. based on a condition (true/false) I need the Data Form to stay on item 2 (or go back to item 2)

    Any ideas would be appreciated.

    Thanks, M
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 10 Nov 2011 Link to this post

    Hello Marcelo,

    I have posted an answer to this inquiry in the other support thread you have opened. In order to achieve a consistent and fruitful dialogue, I would ask you to carry out any further communication there. Thank you.

    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Marcelo
    Marcelo avatar
    40 posts
    Member since:
    Jul 2011

    Posted 14 Nov 2011 Link to this post

    Thanks Ivan. The solution proposed worked well. For others with the same question, please consider the following.

    1) The Data Form does not have "CurrentItemChanging" event, so because of this, we need to use Telerik.Windows.Data.QueryableCollectionView 
    2) After the QueryableCollectionView is instantiated, attach the CurrentChanging event
    3) Within this event, you can access the System.ComponentModel.CurrentChangingEventArgs.Cancel property

    Example:
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            QueryableCollectionView source = new QueryableCollectionView(new List<TestItem>() { new TestItem() { Name = "John" }, new TestItem() { Name = "Jane" }, new TestItem() { Name = "Larry" } });
            source.CurrentChanging += new System.ComponentModel.CurrentChangingEventHandler(source_CurrentChanging);
            radDataForm.ItemsSource = source;
        }
     
        void source_CurrentChanging(object sender, System.ComponentModel.CurrentChangingEventArgs e)
        {
            e.Cancel = false;
        }
     
    }
     
    public class TestItem
    {
        public string Name { get; set; }
    }

Back to Top