Results 1 to 10 of 10

Thread: Trouble cancelling row change in cCJGrid using OnRowChanging

  1. #1
    Join Date
    Jul 2018
    Posts
    1

    Default Trouble cancelling row change in cCJGrid using OnRowChanging

    Based on the Help for OnRowChanging, I believe it is possible to cancel a row navigation by returning true. However, I am having some trouble with this. When I test, it appears as though a new row is created and the focus leaves the grid. When I try to navigate back to the grid by clicking on a cell I get a COM object method invocation error (Error: 4399).

    Do you have to do anything other than function_return true to stop row navigation when using OnRowChanging?

    See below for my OnRowChanging attempt. A few additional notes. In this specific application, I am limited to non-data-aware grids. I use a property to detect if any changes are made and on the row change, call another function that will save the data. I am trying to add error handling so that if an error occurs, I would send an error message and cancel row navigation.


    Code:
    Function OnRowChanging Integer iCurrentSelectedRow Integer iNewRow Returns Boolean
                Boolean bRetVal bSaveRow
                String sSaveStat
                Forward Get OnRowChanging iCurrentSelectedRow iNewRow to bRetVal
                
                Get pbRowSaveStat to bSaveRow
                
                If (bSaveRow) Begin
                    Get UpdateData iCurrentSelectedRow iNewRow to sSaveStat
                    
                    If (sSaveStat <> "OK") Begin
                        Send UserError sSaveStat "Error"
                        Function_Return True
                    End
                    
                End
                
                Set pbRowSaveStat to False
                
                
                Function_Return bRetVal
            End_Function
    Any help would be greatly appreciated.

    Thanks in advance,
    Dan

  2. #2
    Join Date
    Feb 2009
    Location
    SW Connecticut/NY area
    Posts
    9,181

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    DF-19.1 Has anyone figured out what causes this error and why OnRowChanging will not cancel a row change? At least I haven't been able to make it work and am getting the same COM invocation error. This posting was never answered and I've seen at least one other similar one that wasn't either. If this function doesn't work what can be used instead? I tried setting pbAllowAppendRow but haven't found where I can set it in time to stop the row change - a timing issue.
    Bob Worsley
    203-249-2633
    rlworsley at gmail.com

    Do or do not. There is no try. — Yoda

  3. #3
    Join Date
    Mar 2009
    Posts
    1,292

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    It works for me. Show me a reproducible sample where it doesn't work

    Code:
    Use DfAllEnt.pkg
    Use cCJGrid.pkg
    Object oPanel is a Panel
        Set pbSizeToClientArea to True
        Set Size to 200 200
        Object oGrid is a cCJGrid
            Set peAnchors to anAll
            Set Size to 200 200
            Object o1 is a cCJGridColumn
                Set piWidth to 10
            End_Object
            Procedure Activating
                tDataSourceRow[] TheData
                Integer iRow
                Forward Send Activating
                For iRow From 0 to 9
                    Move iRow to TheData[iRow].sValue[0]
                Loop
                Send InitializeData TheData
                Send MovetoFirstRow
            End_Procedure
            Function OnRowChanging Integer iCurrent Integer iNew Returns Boolean
                Boolean bCancel
                Forward Get OnRowChanging iCurrent iNew to bCancel
                If (iNew = 3) Begin
                    Send UserError "Don't touch row 3" "Error"
                    Function_Return True
                End
                Function_Return bCancel
            End_Function
        End_Object
    End_Object
    Start_UI
    Frank Cheng

  4. #4
    Join Date
    Feb 2009
    Location
    SW Connecticut/NY area
    Posts
    9,181

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    Hi Frank
    The only difference between what you're doing and what I'm doing is that I'm using a cjdbgrid which I failed to mention, thinking that it wouldn't make any difference. And it shouldn't. The following does not work, bIsDraw is true and I always end up in the next row. I've got this code in a plain dbcjgrid with no extra code that might affect it. I'll see if I can duplicate it in the examples.

    Code:
              Function OnRowChanging Integer iCurrentSelectedRow Integer iNewRow Returns Boolean
                Boolean bOk bIsDraw
                String  sHasMaster sDraw
                Forward Get OnRowChanging iCurrentSelectedRow  iNewRow to bOk
                Get Field_Current_Value of oWwpro_DD Field Wwpro.Has_master_item to sHasMaster
                Move (Trim(sHasMaster) <> "") to bIsDraw
                If (bIsDraw) Begin            
                    Send UserError "Draw-down proposals can only have the master draw item."
                End
                Function_Return bIsDraw
              End_Function
    And I'm intermittently seeing the following error, both situations are as described in the original posting. It's possible that this error is being thrown only when I'm using the debugger with a breakpoint in this code but I haven't proven that as yet.

    C:\VDF-19.1\Projects\National-DEV\Programs\Main.exe
    COM object method invocation error. Attempt to use object before it's been initialized, pvComObject is NULL.

    Error: 4399

    GET_COMINDEX (7001) - oObject (19309) - at address 48312
    MSG_ONCOMFOCUSCHANGING (8949) - oItems_Grid (19291) - at address 60776
    [start] - at address 324633
    Bob Worsley
    203-249-2633
    rlworsley at gmail.com

    Do or do not. There is no try. — Yoda

  5. #5
    Join Date
    Mar 2009
    Posts
    1,292

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    Here is cDbCJGrid version. It is still working fine for me. Show me a full-blown reproducible sample, or at least reproduce it Order Entry somehow.

    Code:
    Use DfAllEnt.pkg
    Use cDbCJGrid.pkg
    Open "Customer.dat" as Customer
    Object oPanel is a dbModalPanel
        Set pbSizeToClientArea to True
        Set Size to 200 200
        Object oCustomerDD is a DataDictionary
            Set Main_File to Customer.File_Number
        End_Object
        Set Server to oCustomerDD
        Set Main_DD to oCustomerDD
        Object oGrid is a cDbCJGrid
            Set Server to oCustomerDD
            Set Ordering to 1
            Set peAnchors to anAll
            Set Size to 200 200
            Object o1 is a cDbCJGridColumn
                Set piWidth to 10
                Entry_Item Customer.Name
            End_Object
            Function OnRowChanging Integer iCurrent Integer iNew Returns Boolean
                Boolean bCancel
                Forward Get OnRowChanging iCurrent iNew to bCancel
                If (iNew = 3) Begin
                    Send UserError "Don't touch row 3" "Error"
                    Function_Return True
                End
                Function_Return bCancel
            End_Function
        End_Object
    End_Object
    Send Popup of oPanel
    Frank Cheng

  6. #6
    Join Date
    Feb 2009
    Location
    SW Connecticut/NY area
    Posts
    9,181

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    It doesn't seem like we're doing the exact same things, you're basing your logic on the iNew value and I'm doing it based on a DD value. I've modified Order.vw from the examples, simulated my situation and end up with some wonky operation.

    Run the attached, but first find one of the orders with only two line items and delete one of them so that there is only 1 remaining line item. I used order # 104.

    When I click on the blank line or arrow to it I get the error message but I see that the row indicator disappears from the first line, never to return, and the second row shows default 0 values, not that I'm concerned about that. If I click back in the 1st row, depending on the column I eventually get the COM error.

    I guess I can't base not going to a new row on what's in row 1 though I can't quite see what the difference would be.
    Attached Files Attached Files
    Bob Worsley
    203-249-2633
    rlworsley at gmail.com

    Do or do not. There is no try. — Yoda

  7. #7
    Join Date
    Feb 2009
    Location
    SW Connecticut/NY area
    Posts
    9,181

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    It looks like what I really should be using is CanAddRow, this seems to do what I want and no odd errors or odd behavior.
    Bob Worsley
    203-249-2633
    rlworsley at gmail.com

    Do or do not. There is no try. — Yoda

  8. #8
    Join Date
    Mar 2009
    Posts
    1,292

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    This is fascinating. The behavior you described only happens when you are exactly at the bottom row of the grid, and you decide to return "TRUE" in OnRowChanging.

    When the error happens, you might notice that the "currentRow" is -1. The question is how/when did currentRow become -1? For the most part the first time you load up the grid, the piSelectedRow (DAW gets the value from piSelectedRow and pass it to "currentRow" inside "OnRowChanging") in phoDataSource is set to 0 unless you don't have any records in the cDBCjGrid. In your case, you do have a single record in the DetailGrid in order 104.

    Look inside cCJGrid.pkg, procedure OnUnknownAreaClick,

    Look for the following segment

    Code:
                        // down from that row. May append my not
                        If (iRow=iBottomRow) Begin
                            Send LockBeginEdit
                            Send MoveDownRow
                            Send UnlockBeginEdit
    The above code happens before OnRowChanging. Notice this code only executes when you happen to be on the last row. The culprit is "MoveDownRow". It basically adds a new row regardless (because it happens before you can override the behavior in OnRowChanging) and changes piSelectedRow of phoDataSource to -1. By the time you return "True" in OnRowChanging, the remaining code that calls "OnRowChanging" wants to go back to the original row (because you cancel the navigation), which is unfortunately -1, which the cCJGrid tries to get the RecordRow item by passing -1, and it returns NULL instead of a dispatch interface, thus you get all those COM invocation errors.

    Your workaround "CanAddRow" might work with your situation if you are limiting your grid to not to be able to add records. You might be out of luck if you DO allow adding/appending records to the grid.

    Frank Cheng

  9. #9
    Join Date
    Feb 2009
    Location
    Brazil
    Posts
    5,446

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    I confess that I tried allowing the user to leave the grid in the past... I ended giving up. faced several collateral problems .
    Samuel Pizarro

  10. #10
    Join Date
    Feb 2009
    Location
    SW Connecticut/NY area
    Posts
    9,181

    Default Re: Trouble cancelling row change in cCJGrid using OnRowChanging

    Well it's good to know that I'm not just seeing things with this, not good that there seems to be a built-in bug and I bet that it's been there since the beginning. I appreciate that you took the time to look into it. As to CanAddRow, the exact same code I began with at the top of the thread works quite well when replaced with CanAddRow. If the drawdown is a "D" then in this case I don't want the users to be able to add another row. If not a "D" then they are free to add as many as they want and I haven't found any problems with doing so. I put a help desk ticket in for this.
    Bob Worsley
    203-249-2633
    rlworsley at gmail.com

    Do or do not. There is no try. — Yoda

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •