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

How to cancel the Current Item Changed event

2 Answers 178 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Marcelo
Top achievements
Rank 1
Marcelo asked on 09 Nov 2011, 01:11 PM
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 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 10 Nov 2011, 04:42 PM
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 >>
0
Marcelo
Top achievements
Rank 1
answered on 14 Nov 2011, 08:05 PM
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; }
}

Tags
DataForm
Asked by
Marcelo
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Marcelo
Top achievements
Rank 1
Share this question
or