BindingSource and Adding new record

Posted by Admin on 13-Apr-2011 05:11

Hello,

Another question about ProBindingSource.

I've got a PBS (filled by a Query), a DataGridView, a button to add record (which enable textbox), a commit button and a datebound control (textbox for Customer_name).

I just want add new record thanks to PBS.

I'm working with Customer table ( Customer_ns, Customer_name).

Here is my incomplete code:

        pbs = NEW Progress.Data.BindingSource().

        DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
        
        CREATE QUERY hQuery.
        hQuery:SET-BUFFERS(BUFFER Customer:HANDLE).
       
        hQuery:QUERY-PREPARE("PRESELECT EACH Customer NO-LOCK).
        hQuery:QUERY-OPEN.

        pbs:HANDLE = hQuery:HANDLE.

/*...*/

METHOD PRIVATE VOID btAddNewRecord_Click( INPUT sender AS System.Object, INPUT e AS System.EventArgs ):  

       pbs:AddNew().

       RETURN.

END METHOD.

/*...*/

METHOD PRIVATE VOID btCommit_Click( INPUT sender AS System.Object, INPUT e AS System.EventArgs ): 
       pbs:EndEdit().
       pbs:Assign().
       RETURN.
END METHOD.

I don't know how to proceed... How to create Customer and how to assign Customer_ns which hasn't databound control (because it's a number sequence, not editable by the user).

Can you help me to find a simple way to make this?

Thank you.

All Replies

Posted by Admin on 13-Apr-2011 12:15

You'll have to handle the CreateRow and CancelCreateRow events.

Did you check the "GUI for .NET Programming" doc available here: http://communities.progress.com/pcom/docs/DOC-103525

The events are described on page 4-41 and there's a complete sample starting at 4-44.

Posted by Admin on 18-Apr-2011 08:28

I finally use the createRow event.

        bsCustomer = NEW Progress.Data.BindingSource().

        DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
       
        CREATE QUERY hQuery.
        hQuery:SET-BUFFERS(BUFFER Customer:HANDLE).
        hQuery:ADD-BUFFER(BUFFER Adres:HANDLE).
      
        hQuery:QUERY-PREPARE("PRESELECT EACH Customer NO-LOCK, FIRST Adres OF Customer NO-LOCK).
        hQuery:QUERY-OPEN.

        bsCustomer:HANDLE = hQuery:HANDLE.

/*...*/

DO TRANSACTION ON ERROR UNDO , RETURN
            ON STOP UNDO , RETURN :
          
            hbsCustomer = bsCustomer:Handle.
            hBuffCust = hbsCustomer:GET-BUFFER-HANDLE ("Customer").  
            IF hBuffCust:BUFFER-CREATE () THEN DO:
                hBuffCust::customer_ns = NEXT-VALUE(CUSTOMER_SEQ).


                /*******No BUFFER-CREATE for Adres because Adres may already exist******/

   
                hbsCustomer:CREATE-RESULT-LIST-ENTRY ().
            END.
END.

But with multiple buffers as above, it's more complicated. When I create new buffer Customer, no Adres buffer exists => error because Inner Join isn't satisfied!

So, I use a tip. Just before the CREATE-RESULT-LIST-ENTRY method :

hBuffCust = hbsCustomer:GET-BUFFER-HANDLE ("Adres").
hBuffCust:FIND-FIRST ("",NO-LOCK).

And when I commit, I re-assign to the correct Adres Buffer.

I don't think it's the best and cleanest solution but that's all I've found.

This thread is closed