Try OpenEdge Now
skip to main content
GUI for .NET Programming
Binding ABL Data to .NET Controls : Understanding the ProBindingSource : Data binding examples : Buffer binding example
 
Buffer binding example
BufferBinding.p uses a ProBindingSource to bind fields from the Customer table to .NET UI controls. First, the procedure gets the handle of the Customer table buffer. Then, it creates the ProBindingSource. Finally, it binds the text boxes to the ProBindingSource through their DataBindings property.
/* BufferBinding.p
    Bind to a buffer on the Sports2000.Customer table and display some fields
    on a simple form. */

/* USING statements must be the first in the procedure. Note that you could
   have USING statements for the OpenEdge classes also.*/
USING System.Windows.Forms.*.

DEFINE VARIABLE rMainForm  AS Progress.Windows.Form       NO-UNDO.
DEFINE VARIABLE rBindS     AS Progress.Data.BindingSource NO-UNDO.
DEFINE VARIABLE rControls  AS Control+ControlCollection   NO-UNDO.
DEFINE VARIABLE numTBox    AS TextBox NO-UNDO.
DEFINE VARIABLE nameTBox   AS TextBox NO-UNDO.
DEFINE VARIABLE phoneTBox  AS TextBox NO-UNDO.
DEFINE VARIABLE numLabel   AS Label   NO-UNDO.
DEFINE VARIABLE nameLabel  AS Label   NO-UNDO.
DEFINE VARIABLE phoneLabel AS Label   NO-UNDO.
DEFINE VARIABLE bCustHdl   AS HANDLE  NO-UNDO.

bCustHdl = BUFFER Sports2000.Customer:HANDLE.

FIND FIRST Customer.rBindS = NEW Progress.Data.BindingSource(bCustHdl).

/* Main block */
IF VALID-OBJECT(rBindS) THEN
  DO ON ERROR UNDO, LEAVE:

    rMainForm        = NEW Progress.Windows.Form().
    rMainForm:Width  = 300.
    rMainForm:Height = 200.
    rMainForm:Text   = "Customer Form".
    numTBox          = NEW TextBox().
    numTBox:Left     = 50.
    numTBox:Top      = 40.
    numTBox:Width    = 50.
    numTBox:Height   = 40.
    numTBox:Name     = "numcntl".
    numTBox:ReadOnly = TRUE.

    numLabel        = NEW Label().
    numLabel:Left   = 25.
    numLabel:Top    = 45.
    numLabel:Width  = 75.
    numLabel:Height = 15.
    numLabel:Text   = "Customer #:".

    nameTBox        = NEW TextBox().
    nameTBox:Left   = 50.
    nameTBox:Top    = 60.
    nameTBox:Width  = 150.
    nameTBox:Height = 40.
    nameTBox:Name   = "namecntl".

    nameLabel        = NEW Label().
    nameLabel:Left   = 25.
    nameLabel:Top    = 65.
    nameLabel:Width  = 75.
    nameLabel:Height = 15.
    nameLabel:Text   = "Customer:".

    phoneTBox        = NEW TextBox().
    phoneTBox:Left   = 50.
    phoneTBox:Top    = 80.
    phoneTBox:Width  = 100.
    phoneTBox:Height = 40.
    phoneTBox:Name   = "phonecntl".

    phoneLabel        = NEW Label().
    phoneLabel:Left   = 25.
    phoneLabel:Top    = 85.
    phoneLabel:Width  = 50.
    phoneLabel:Height = 15.
    phoneLabel:Text   = "Phone #:".

    rControls = rMainForm:Controls.
    rControls:Add(numTBox).
    rControls:Add(numLabel).
    rControls:Add(nameTBox).
    rControls:Add(nameLabel).
    rControls:Add(phoneTBox).
    rControls:Add(phoneLabel).

    numTBox:DataBindings:Add("Text", rBindS, "CustNum").
    nameTBox:DataBindings:Add("Text", rBindS, "Name").
    phoneTBox:DataBindings:Add("Text", rBindS, "Phone").

    WAIT-FOR Application:Run(rMainForm).

END. /* Main block */
When this procedure runs, a simple form appears displaying the first customer's number, name, and phone number, as shown in the following figure.
Figure 12. Form bound to database buffer