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

Original Value

3 Answers 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daniel
Top achievements
Rank 2
Daniel asked on 02 Nov 2009, 02:27 PM
Hello
how is it possible to access a field's original value?

I've got a bound ComboBox on a Windows Form. After the SelectedIndexChanged event of the ComboBox fires, my code check's some business rules. In some cases the change of the field that is bound to the ComboBox need's to be canceled. Then the original value of the field, that the ComboBox is bound to, need's to be assigned again.

Any ideas?

Kind regards
Mike

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 05 Nov 2009, 12:46 PM
Hi Daniel,

You can subscribe to the IObjectScope Changing event. This even occurs when an persistent object is about to be changed. There you can perform your logic and if everything is fine you can allow the change to be done. If you, based on your business logic, decide that this change should not be done you can cancel the event by throwing an exception.
static void Main(string[] args)
       {
           IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
           scope.Tracking.Changing += new ChangeEventHandler(Tracking_Changing);
           scope.Transaction.Begin();
           //some action.
           scope.Transaction.Commit();
        
       }
 
       static void Tracking_Changing(object sender, ChangeEventArgs e)
       {
           //bussines logic goes here.
       }
Note that you have access to the changed field via the OldValue property of the ChangeEventArgs.

All the best,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Daniel
Top achievements
Rank 2
answered on 12 Nov 2009, 10:35 AM
Hi Petar
thank you very much!

Is there no other way to access the original value? I don't want to track, the change of an object. I want to access the original value of an object any time in my code.

Kind regards
Mike
0
PetarP
Telerik team
answered on 13 Nov 2009, 11:10 AM
Hi Daniel,

I am afraid but currently there is no other way to access the original value of an object but to track its changes. We are sorry for any inconvenience this might be causing.

Sincerely yours,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 2
Answers by
PetarP
Telerik team
Daniel
Top achievements
Rank 2
Share this question
or