Delete Row In Matrix

Hello All,
I have a UDO and a form for it. The UDO has a child table, which is binded to a matrix in the form. Everything works well except Delete Row in the matrix.
If I don't do anything when Delete Row menu is clicked, the row is deleted. But as soon as Update button is clicked, a new empty row gets added to the matrix and the underlying table.
The same happens even if I catch the delete row event, do the delete myself and then set the bubbleevent to false.
Is this the default behaviour. What is the workaround to avoid this addition of new empty row.
Following is the code I am using for deleting the row. I've used various combinations of this code to the same affect.
        Dim oMatrix As SAPbouiCOM.Matrix
        Dim RowIndex As Integer
        Try
            If oForm.Mode <> SAPbouiCOM.BoFormMode.fm_FIND_MODE Then
                oMatrix = oForm.Items.Item("AC_MX01").Specific
                RowIndex = oMatrix.GetNextSelectedRow
                If RowIndex <= 0 Then
                    Exit Sub
                End If
                oForm.DataSources.DBDataSources.Item("@AC_SMP1").RemoveRecord(RowIndex - 1)
                oMatrix.DeleteRow(RowIndex)
                'oMatrix.FlushToDataSource()
                'oMatrix.LoadFromDataSource()
            Else
                Exit Sub
            End If

Hi Rahul
Try this code
        Dim oMatrix As SAPbouiCOM.Matrix
        Dim RowIndex As Integer
        oMatrix = oForm.Items.Item("AC_MX01").Specific
        For RowIndex = 1 To oMatrix.RowCount
             If oMatrix.IsRowSelected(RowIndex) = True Then
                 oMatrix.DeleteRow(RowIndex)
                 oMatrix.FlushToDataSource()
                 If form.Mode = 1 Then form.Mode = BoFormMode.fm_UPDATE_MODE
                 Exit For
             End If
       Next
Hope this helps....
Kind Regards
Arun TB

Similar Messages

  • Deleting row in matrix.

    Hello.
    I have weird problem.
    If I add some rows to matrix, and then delete rows the method with:
    m_pMatrix->GetRowCount();
    return the number of rows without delete.
    For example:
    If i have matrix with 5 rows, and I delete 2 rows, method with GetRowCount show me 5
    What is wrong ?
    I solved this problem with adding new variable, but why does it work wrong ?
    Sorry for my english.
    Regards
    Kamil Wydra

    Hello.
    Thank You for Your response.
    I try that and it works.
    Thanks again.
    Regards
    Kamil Wydra

  • Delete row of matrix

    i have created amatrix. but when i delete a particular line by clicking on delline error reflects as
    matrix-invalid row no
    form generated via udo form generator

    thanks for the reply. it really helped me and i got my problem solved.

  • [Help]Grid (Add row - Delete row)

    Hi experts. Just want to ask how can I add row and delete row in Grid?
    And how can I get the data from the specific row so I can Save the data in my table.
    Please help.

    Hi  hikaru1207     ,
          this code for delete row from Matrix :
                 Matrix oMatrix_cat = (Matrix)form.Items.Item("mtx_cat").Specific;
    Delete Row -
               for (int i = 2; i <= oMatrix_cat .rowcount; i++)
                        oEditText = (EditText)oMatrix.Columns.Item(colname).Cells.Item(i).Specific;
                            oMatrix.DeleteRow(i);
                 if (form.Mode == BoFormMode.fm_ADD_MODE)
                        if (oMatrix.RowCount == 0)
                            DBDataSource oDBDataSource = form.DataSources.DBDataSources.Item(table name);
                            oDBDataSource.Clear();
                    oMatrix_cat .FlushToDataSource();
    Add row----
                       if (oMatrix_cat.RowCount == 0)
                                oMatrix_cat.AddRow(1, 1);
                                oDBDataSource_cat.InsertRecord(oDBDataSource_cat.Size);
                            else
                                oDBDataSource_cat.InsertRecord(oDBDataSource_cat.Size - 1);
                            oDBDataSource_cat.SetValue("LineId", oDBDataSource_cat.Size - 1, "");
                            oDBDataSource_cat.SetValue("U_SKU", oDBDataSource_cat.Size - 1, "");
                            oDBDataSource_cat.SetValue("U_CatId", oDBDataSource_cat.Size - 1, "");
                            oMatrix_cat.LoadFromDataSource();
                            oDBDataSource_cat = null;
                   please reply ......
    yhanks
    surajit

  • Deleting row from a table binded to a matrix

    Hi all
    i have a form with a matrix binded to a user table which is handled as a Master Data lines by UDO.
    i want to enable deleting lines from the table by selecting a row in the matrix and clicking a delete button.
    currently i'm handling the click event by usint the method DeletRow of the matrix object.
    when i press the Update button (UID = "1"). the fact that a row was deleted from the matrix does not affect the bounded table.
    my question is how in code can i cause the deletion of a row from the matrix to also be deleted from the database table?
    appreciate the help
    Yoav

    Hi Yechiel
    flushToDatasource make the following:
    Flushes current data from the GUI to the bounded data source using the following process:
    1)Cleans the data source.
    2)Copies each row from the matrix to the corresponding data source record.
    In other words: This method load data from Matrix to DataSource (but not to database)
    the next step is update database from userdatasource
    Note: You migth read sdk help for more information

  • Delete row matrix in UDO Form

    Hi All,
    I've created a simple form based on an registered UDO (2 tables: Document and Document Lines).
    This form contains a matrix bounded to the lines of my UDO document.
    Everything works fine except the Delete button that should delete a document line in the matrix: it never
    deletes the lines from database, although it deletes them from the form. But if I select again the same
    record, the deleted line is show again!
    My code is very simple:
    void btRemove_ClickEvent()
         // Remove selected row from Matrix
         SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix) oForm.Items.Item("mxMatrix").Specific;
         int iPos = oMatrix.GetNextSelectedRow( 0, SAPbouiCOM.BoOrderType.ot_RowOrder );
         if( iPos > -1 )
              oMatrix.DeleteRow( iPos );
              oMatrix.FlushToDataSource();
              oForm.Update();
    What is the problem with my code? Is it missing something?
    Regards,
    Manuel Dias

    Thanks Gianluigi,
    By the way, I want to delete the Matrix line with DI API has you suggest, so I was thinking in using this code:
         SAPbobsCOM.UserTables pUT = Main.oSBOCompany.UserTables;
         SAPbobsCOM.UserTable dt = pUT.Item("@PDWC_LINE");
         bool xx = dt.GetByKey( sKey );
         int res = dt.Remove();
    The problem is that UserTable object, has a GetByKey() method that works only for user tables whose PK
    contains only one column (GetByKey requires only a single value).
    Since my table is created in SBO with the UDO Document Lines template, the PK is composed automatically
    by Code and LineId columns, so the GetByKey() method does not allow me to select a specific record in
    order to delete it next.
    Do you know any workaround for this? Of course I could user the Recordsed object and write SQL to
    delete my table line, but I think it must be an esay way to do this....
    Regards,
    Manuel Dias

  • Delete Last Row in Matrix on SBO 2005

    Hi,
    Im using SAPB1 2005 SP1 with B1DE.
    I've seen a post that indicates that the following code should delete a row from a matrix (even the last row) when using SBO 2005
    I still find that all rows except last row of matrix are removed from the database.
    <b>How do I delete the last row from the Del button event handler????</b>
    I'm using
    <i>        [B1Listener(BoEventTypes.et_CLICK, false)]
            public virtual void OnAfterClick(ItemEvent pVal)
                bool ActionSuccess = pVal.ActionSuccess;
                Form form = B1Connections.theAppl.Forms.Item(pVal.FormUID);
                Item item = form.Items.Item("del");
                Button button = ((Button)(item.Specific));
                // ADD YOUR ACTION CODE HERE ...
                int row;
                Matrix oMtx = (Matrix)form.Items.Item("mtx_0").Specific;
                DBDataSource oDBDS = (DBDataSource)form.DataSources.DBDataSources.Item("@SD_POOLCONTRCT_LINE");
                row = oMtx.GetNextSelectedRow(0, BoOrderType.ot_SelectionOrder);
                oMtx.DeleteRow(row);
                if (oMtx.RowCount == 0)
                    oDBDS.RemoveRecord(0);
                if ((form.Mode != BoFormMode.fm_ADD_MODE) | (form.Mode != BoFormMode.fm_UPDATE_MODE))
                    form.Mode = BoFormMode.fm_UPDATE_MODE;
                }</i>

    Hi Ben,
    [B1Listener(BoEventTypes.et_CLICK, false)]
    public virtual void OnAfterClick(ItemEvent pVal)
    bool ActionSuccess = pVal.ActionSuccess;
    Form form = B1Connections.theAppl.Forms.Item(pVal.FormUID);
    Item item = form.Items.Item("del");
    Button button = ((Button)(item.Specific));
    // ADD YOUR ACTION CODE HERE ...
    int row;
    Matrix oMtx = (Matrix)form.Items.Item("mtx_0").Specific;
    DBDataSource oDBDS = (DBDataSource)form.DataSources.DBDataSources.Item("@SD_POOLCONTRCT_LINE");
    Rest of your code will remain same.
    I am making the modification here. I am using the RowCount property that gives me the address of the last row of the matrix.
    <b>row = oMtx.RowCount;</b>
    Every time this will return you the last row and that row will be deleted.
    <b>row = oMtx.RowCount;</b>
    oMtx.DeleteRow(row);
    if (oMtx.RowCount == 0)
    oDBDS.RemoveRecord(0);
    if ((form.Mode != BoFormMode.fm_ADD_MODE) | (form.Mode != BoFormMode.fm_UPDATE_MODE))
    form.Mode = BoFormMode.fm_UPDATE_MODE;
    Regards,
    Prashant

  • Can't catch the matrix row for Deleting Rows

    Hi,
    I've already read related topics but couldn't solve the problem.
    I catch the Delete Row menu event 1293, but then I can't save the deleted row in an array since it's no longer listed as a selected row.
    All the matrix rows return
    oMatrix.IsRowSelected(i) = False after catching that 1293 event.  
    Trying BeforeAction True or false didn't solve that problem.
    What am I missing ?

    it sounds like a bug.
    here is workaround: in oMatrix-itempress event try to store selected rowIndex in your variable - so, when you catch 1293-menuEvent you'll know which row you should save - it'll be value of your variable.

  • Delete Row (1293) always disabled with matrix

    I have a maxtrix whose menu-item 'Delete Row' (menu uid 1293) is always
    disabled, even though its 'AllowRowDelete'-property is set to 'true'.
    What could be the problem here ?
    (I have several other matrixes on which it just works fine,
    only on this one matrix, I cannot get it to work. Very strange).

    ok,
    than enable the menuUID with
    oForm.EnableMenu "1293", True
    but you have to program the remove line function by yourself
    regards
    David

  • Matrix Delete Row

    Good Afternoon
    Experts:
    After some review of handling the updating of a Matrix with the help of Neftali, I had another thought on the topic.  The actual update of a row is no problem.  However, the delete of a row presents a bit of a quandry.  While it can be done,  this way be seems ok:
    <b>Scenario1:</b>
    1)Add a delete button to the screen
    2)Click on the grey column on the left of the Matrix. 
    3)The Matrix row gets highlighted and the Delete button is enabled
    4)Hit the button to delete the row and then in code behind the button
      go delete the record from the table
    **Problem is I cannot figure out how to get the whole row to highlight when I click
      in the leftmost grey column in the Matrix
    <b>Scenario2:</b>
    1)I enabled the delete row right for the Matrix with  MatReqForm.EnableMenu("1293", True)
    2)Using the MenuEvent, I can trap the event and ask the user if the DELETE is for sure using a message box.  However, the data is already gone from the Matrix at this point.
    So, I think highlighting the whole row and hitting a delete button may work better...unless I am missing something in Scenario2.
    Thoughts...questions?
    Thanks,
    EJD

    Hi Ed,
    You could trap the right-click event and add your own Delete Row option to the menu (there's an example of how to use the right-click event in the SDK samples). If it's your own menu option then you have full control on when the row is deleted so you can prompt the user to confirm the deletion and only delete after they say yes. My own preference would be a right-click menu option but a button is another good option.
    Highlighting a row is easy as SBO does it all for you. It's just a case of setting the correct value to the SelectionMode property of the matrix (setting it to 1 will allow the user to select multiple rows, 2 and they can select only a single row).
    Kind Regards,
    Owen

  • DELETE MULTIPLE ROWS FROM MATRIX

    Hi all,
    I´M DESPERATED.
    I am able to delete row by row in my matrix, but ¿Could anyone post a sample to delete multiple rows?
    I´ve been trying several ways but it doesn´t work.
    My code is:
    ========================
      Dim i As Long = oMatrix.GetNextSelectedRow
                    If i > -1 Then
                        If oMatrix.IsRowSelected(i) = True Then
                            oMatrix.DeleteRow(i)
                        End If
    ========================
    Thank you in advanced,
    lorenzo

    Don´t worry, It was a problem with my loop.
    Thanks anyway
    lorenzo

  • Delete row menu on sales line item matrix

    Can anyone tell me how I can tell which row is being deleting by the menu event for this delete row ( MENU ID 1293)
    I want to access the record on the menu event and check some fields but the user does not always have to have a row selected to use this menu. If I put the cursor in the item code field on the first line item even though the row is not selected and hit delete row it will delete the 1st row.
    Any ideas?

    Thanks for the posting John. I guess I can also use the right click event to get the row?
    Would this work the same?
    currently i am using
    int selRow = myMat.GetNextSelectedRow(0,SAPbouiCOM.BoOrderType.ot_RowOrder);
    but of course there isn't always a row selected when the user selects delete

  • Adding a row in Matrix

    Hi,
    I have a Form having matrix, and it is bind with 2 UDT Tables. One of 'Master Type' and Other is 'Master Data Lines'.
    All the operation 'ADD,UPDATE,FIND,DELETE, ADD ROW' and the operation for Navigation Buttons are working fine.
    But when I navigate to any previous record,following problem arises :
    1. When i add row to matrix it copies data from the previous row.
    2. Now after 1st operation i change the newly added row , due to this form goes in Update mode.It is also fine.But when i press the Update Button i get the message records updated successfully, but the problem is newly added row in the matrix does not inserted in DataBase
    I need the solution for both problems.
    Thanks in advance.

    Here some sample I used to test it:
    Case SAPbouiCOM.BoEventTypes.et_KEY_DOWN
                            Dim l_Mat As SAPbouiCOM.Matrix
                            l_Mat = oForm.Items.Item("Matrix2").Specific
                            If pVal.CharPressed = 13 And (pVal.Row = l_Mat.RowCount) Then
                                Dim _UDSS As SAPbouiCOM.UserDataSources
                                ' Clear the UDS before adding a new line
                                _UDSS = oForm.DataSources.UserDataSources
                                UDSS.Item("UDSCode").ValueEx = ""
                                UDSS.Item("UDSName").ValueEx = ""
                                UDSS.Item("UDSPhone").ValueEx = ""
                                l_Mat.AddRow()
                            End If
    If you are using DBDatasources is easier (1st post)
    Regards,
    Felipe

  • Delete row

    Hi
    Is it possible to delete a row using DI ??? I think no...
    But if no, <b>then how system form manage it</b>. If we delete any row from system matrix, it is also deleted from DBase also.....

    Hi,
    there are many possibilities, for deleting row ... in system form, easiest and perhaps safiest way is to simulate "Ctrl-K"
    in custom form, with DBDatasource, you have to delete it on your own I've tried the Ctrl-K, but it isn't doing anything, from DBDatasource for visualisation and from Database ...
    Or perhaps, only delete it from Database, and requery and reload DBDatasource ?
    conclusion: I also think, that it is impossible to delete row from your own form ...
    Jaro

  • How to add or delete rows in tablecontrol?

    Hi,
    I am using a tablecontrol to enter data records.
    I want to use 2 buttons, one to insert a row into a tablecontrol and another to delete a selected row of a tablecontrol.
    How do I insert or delete rows of a tablecontrol?
    Thanks.

    Hi Kumar,
    Please look at the below sections......
    ADDING BLANK LINES
    To add blank lines to table control we do not need to change any of the fields of the structure CXTAB_CONTROL simply adding blank lines to the internal table will do.
    INSERT INITIAL LINE INTO itab.
    DELETING SELECTED ROWS
    Deletion of selected rows is simple. To delete selected rows first we will determine the rows which have been selected through selection column .
    FOR SINGLE ROW SELECTION
    IF mark EQ 'X' .             "mark is the name of selection column field
    DELETE itab FROM workarea . 
    ENDIF.
    FOR MULTIPLE ROW SELECTION
    *To deetermine the rows selected we will use the selection column field to loop
    *through the internal table.
    LOOP AT itab WHERE mark EQ 'X'.  "mark is the name of selection column field
    DELETE itab                                    " and is part of the internal table .
    ENDLOOP.
    Thanks,
    Ravi Kanth

Maybe you are looking for