View previous topic :: View next topic |
Author |
Message |
mike_girkin
Joined: 11 May 2011 Posts: 7
|
Posted: Wed May 11, 2011 11:01 am Post subject: GetControlValue event fired twice |
|
|
Why does the GetControlValue event fired twice on each edit? Is it the correct behaviour?
The problem is the following: I have got a VirtualTree binded to DataSet, and I want to warn user after editing with a message box, using which he can confirm or decline the changes, But the GetControlValue event fired twice! So that the message box is shown twice!
Can I implement desired behaviour without using some "hacky" ways of using flags or something else?
PS. VirtualTree ver.4 |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed May 11, 2011 10:59 pm Post subject: |
|
|
GetControlValue is not really intended as the point to do validation. The way to handle this is to add a Validating event handler to the actual editor control. See the following thread for more information:
http://www.infralution.com/phpBB2/viewtopic.php?t=1039 _________________ Infralution Support |
|
Back to top |
|
|
mike_girkin
Joined: 11 May 2011 Posts: 7
|
Posted: Fri May 13, 2011 8:59 am Post subject: |
|
|
The problem is that I am able only to cancel the saving the value by setting e.Cancel to True. Setting e.Cancel to True only allows me to force the user to continue editing.
What I want is - a Yes-no dialog is shown to the user, and if user presses the "No" button - value doesnt change, on "Yes" - changes. But the editing in both cases is finished.
Is it possible to implement this workflow using virtual tree? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri May 13, 2011 10:49 am Post subject: |
|
|
The reason GetControlValue gets called twice is that VirtualTree updates the data in two circumstances - when the editor value changes (by handling the changed event on the control) and then when editing completes. If you don't care about updating the data when the editor value changes but editing hasn't completed then you could eliminate the handling of the value changed event. To do this you would need to create a custom CellWidget (see help for details on doing this) and override the
OnEditorValueChanged method to do nothing. Then your original approach would work.
Another option would be derive your own custom control. Override (or shadow) the property that sets the control value and save the original value. Then override the OnValidating method and display your message box. If they respond "No" then revert the value to the original value. _________________ Infralution Support
Last edited by Infralution on Fri May 13, 2011 11:00 am; edited 2 times in total |
|
Back to top |
|
|
mike_girkin
Joined: 11 May 2011 Posts: 7
|
Posted: Fri May 13, 2011 10:56 am Post subject: |
|
|
I've recently implemented the desirable behaviour, by calling the AbandonEdit() method of the virtual tree, when it is neccessary to finish the edit process without saving the data.
Many thanks for your help! |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri May 13, 2011 10:59 am Post subject: |
|
|
I just updated my earlier reply to you above - it might only be academic interest if you have solved the issue. _________________ Infralution Support |
|
Back to top |
|
|
|