Try OpenEdge Now
skip to main content
GUI for .NET Programming
Binding ABL Data to .NET Controls : Understanding the ProBindingSource : Data binding examples : Query binding example
 
Query binding example
QueryBinding.p uses a ProBindingSource to bind a query on the Customer table to a grid. First, the procedure creates the query. Then, it creates the ProBindingSource. To disable edits, the procedure sets the ProBindingSource's AllowEdit and AllowRemove properties to FALSE. It does not need to set AllowNew because adding new rows is disabled by default in the grid's properties. Finally, it binds the grid to the ProBindingSource through the grid's DataSource property.
/* QueryBinding.p
   Bind to a Customer query and display the entire table in an Infragistics UltraWinGrid */
/* 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.*.
USING Infragistics.Win.UltraWinGrid.*.

DEFINE VARIABLE rMainForm  AS Progress.Windows.Form       NO-UNDO.
DEFINE VARIABLE rCustGrid  AS UltraGrid                   NO-UNDO.
DEFINE VARIABLE rBindS     AS Progress.Data.BindingSource NO-UNDO.
DEFINE VARIABLE controls   AS Control+ControlCollection   NO-UNDO.

DEFINE VARIABLE hCustQuery AS HANDLE                      NO-UNDO.

CREATE QUERY hCustQuery.hCustQuery:SET-BUFFERS(BUFFER Customer:HANDLE).
hCustQuery:QUERY-PREPARE("PRESELECT EACH Customer").
hCustQuery:QUERY-OPEN.

/* This will display all of the Customer fields in the grid. */
rBindS = NEW Progress.Data.BindingSource(hCustQuery).

/* Alternately, specify fields using the optional include-fields and
   except-fields lists. */

/* rBindS = NEW Progress.Data.BindingSource(hCustQuery,
       "CustNum,Name,Address,City,PostalCode,Phone,Contact,Salesrep",""). */
/* Disable editing because procedure does not include event logic to handle
   changes. */
rBindS:AllowEdit = FALSE.
rBindS:AllowRemove = FALSE.

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

    rMainForm        = NEW Progress.Windows.Form().
    rMainForm:Width  = 840.
    rMainForm:Height = 500.
    rMainForm:Text   = "Customer Form".

    rCustGrid            = NEW UltraGrid().
    rCustGrid:Left       = 10.
    rCustGrid:Top        = 10.
    rCustGrid:Width      = 810.
    rCustGrid:Height     = 420.
    rCustGrid:Name       = "CustomerGrid".
    rCustGrid:Text       = "Customer Grid".
    rCustGrid:DataSource = rBindS.
    rCustGrid:TabIndex   = 1.

    controls = rMainForm:Controls.
    controls:Add(rCustGrid).

    WAIT-FOR Application:RUN(rMainForm).
END. /* Main block */
When the procedure runs, a simple form appears displaying a customer grid, as shown in the following figure.
Figure 11. Grid bound to query