Bind GUI value to data source

Posted by Froy on 24-Feb-2010 08:55

Hi !

I'm trying to update a datasource linked to a texteditor, while i'm changing the value inside this texteditor.

But the data in the datasource remains the same, until I quit the field.

I guess that the synchronizing magic happens only on the "on leave texteditor" event... But is there anyway to configure that ? What if I need the sync to happen on the "on value changed" event (without building my own BindingSource objecy) ?

Thanks

Dam

All Replies

Posted by Peter Judge on 24-Feb-2010 09:07

You could add a ValueChanged event handler and call bindingSource1:Assign(), or set the bindingSource1:InputValue if you wanted to.

But why do you need to assign every input character into the TT?

-- peter

Posted by Froy on 24-Feb-2010 09:26

I'm already doing an Assign() on the "value change" event.

If I try removing it, the data is not updated even on leaving the cell...

Posted by Froy on 24-Feb-2010 09:38

I need it, for axample, in order to save data I've juste typed by clicking on a save button with the property "accept focus" set to false (which means the field has not been leaved).

Posted by Admin on 24-Feb-2010 10:02

Something like

oTextBox:DataBindings["Text"]:WriteValue().

should do. Let me know if not, then I'll look up the exact code.

Posted by Admin on 24-Feb-2010 10:25

froy schrieb:

I need it, for axample, in order to save data I've juste typed by clicking on a save button with the property "accept focus" set to false (which means the field has not been leaved).

This is the code that we are using for that exact purpose:

    /*------------------------------------------------------------------------------

        Purpose: Recursive call WriteValue method of all DataBinding objects.

                 Initialy called by SaveChanges () of SmartViewerControl.

                 Parameters:

                     poControl   -   System.Windows.Forms.Control

                                     Current Container to perform Action on.

        Notes:   This ensures, that the currently focussed field values are

                 written to the bindingsource as well (toolbar buttons do

                 not cause a Leave to a textbox) .

    ------------------------------------------------------------------------------*/     

    METHOD PROTECTED VOID RecurseBindingWriteValue(poControl AS Control):

                 

        DEFINE VARIABLE oControl            AS System.Windows.Forms.Control            NO-UNDO.

        DEFINE VARIABLE oBindingsCollection AS System.Windows.Forms.BindingsCollection NO-UNDO .                   

        DEFINE VARIABLE cPropertyName       AS CHARACTER                               NO-UNDO.

        DEFINE VARIABLE i                   AS INTEGER                                 NO-UNDO.

        DEFINE VARIABLE j                   AS INTEGER                                 NO-UNDO.

          

        DO i = 0 TO poControl:Controls:Count - 1:

            /* Write Changes to the current field */

            ASSIGN

                oControl            = poControl:Controls[i]

                oBindingsCollection = oControl:DataBindings.

            DO j = 0 TO oControl:DataBindings:Count - 1:

                ASSIGN

                    cPropertyName = oBindingsCollection:Item[j]:PropertyName .

                oControl:DataBindings[cPropertyName]:WriteValue().

            END.

            IF oControl:Controls:Count > 0 THEN

                RecurseBindingWriteValue (oControl) .

        END.

          

        RETURN.

    END METHOD.

Typically in our framework input fields are arranged in UserControls (SmartViewerControls). The method is recursive (so that it works with all kinds of Panels ect.) and we call it from within that UserControl with
RecurseBindingWriteValue (THIS-OBJECT).
This ensures that all fields that have bound properties write back their values to the BindingSource. The Assign() method of the BindingSource can then properly assign the Buffer of the ABL data source (temp-table or database record).

Posted by Froy on 25-Feb-2010 02:09

Thank you everybody for your answers ! It helps on two points :

- I'm not alone with thoses questions

- I got an answer

Wouh !

This thread is closed