Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GetControlValue event fired twice

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
mike_girkin



Joined: 11 May 2011
Posts: 7

PostPosted: Wed May 11, 2011 11:01 am    Post subject: GetControlValue event fired twice Reply with quote

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
View user's profile Send private message AIM Address
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed May 11, 2011 10:59 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mike_girkin



Joined: 11 May 2011
Posts: 7

PostPosted: Fri May 13, 2011 8:59 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri May 13, 2011 10:49 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mike_girkin



Joined: 11 May 2011
Posts: 7

PostPosted: Fri May 13, 2011 10:56 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri May 13, 2011 10:59 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group