cancel
Showing results for 
Search instead for 
Did you mean: 

delete last matrix row

Former Member
0 Kudos

I have read and tried all the threads I could find on this subject and I still am not able to delete the last row in my UDO matrix. I am including a section of my code (in C#) including all the various attempts that have been commented out as I tried them. Can someone help me out? My SAP B1 version is 2005 A (6.80.318) SP:01 PL:14.


                    if ((pVal.ItemUID == "del") & (pVal.EventType == BoEventTypes.et_ITEM_PRESSED))
                    {
                        Form oForm = B1Connections.theAppl.Forms.Item(FormUID);
                        if (oForm.PaneLevel == 1)
                        {
                            Item oItem = oForm.Items.Item("mtx_0");
                            Matrix oMatrix = ((Matrix)(oItem.Specific));
                            Columns oColumns = oMatrix.Columns;
                            for (int i = 1; i <= oMatrix.VisualRowCount; i++)
                            {
                                if (oMatrix.IsRowSelected(i) == true)
                                {
                                    // oMatrix.ClearSelections();
                                    
                                    //Column oCol = oColumns.Item("col_f");
                                    //oEdit = ((EditText)(oCol.Cells.Item(i).Specific));
                                    //int oRowNo = int.Parse(oEdit.Value.ToString());
                                    //oEdit.Value = "";

                                    oMatrix.DeleteRow(i);
                                    oMatrix.FlushToDataSource();
                                                                                if (oMatrix.RowCount == 1)
                                    {
                                        oMatrix.Clear();
                                        oMatrix.FlushToDataSource();

                                    //    DBDataSource oDBDS = ((DBDataSource)(oForm.DataSources.DBDataSources.Item("@CIP_OHSL")));
                                    //    try
                                    //    {
                                    //        int ii = 0;
                                    //        oDBDS.RemoveRecord(ii);
                                    //    }
                                    //    catch (System.Exception er)
                                    //    {
                                    //        B1Connections.theAppl.MessageBox(er.ToString(), 0, "OK", "", "");
                                    //    }
                                    }

                                    oMatrix.LoadFromDataSource();

                                    // oMatrix.DeleteRow(i);
                                    // oMatrix.FlushToDataSource();
                                    
                                    // oMatrix.FlushToDataSource();
                                    // oMatrix.LoadFromDataSource();
                                    // oMatrix.DeleteRow(i);
                                    // oMatrix.LoadFromDataSource();

                                    if (oForm.Mode != BoFormMode.fm_ADD_MODE)
                                    {
                                        oForm.Mode = BoFormMode.fm_UPDATE_MODE;
                                    }
                                    break;
                                }
                            }
                        }
                        //oForm.Update();
                        BubbleEvent = false;
                    }

Thanx!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

My SAP B1 version is 2005 A (6.80.318) SP:01 PL:14.

The line disappears from the form but reappears when the data browser brings up the

matrix again.

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

I have tested with 2005 SP01 PL18 and it works fine, please try with it.

Regards

Trinidad.

Answers (2)

Answers (2)

Former Member
0 Kudos

Tried the example that I found (included below) but the last line still won't delete from the data source.


if (form.Mode != BoFormMode.fm_FIND_MODE)
      {

        form.Freeze(true);

        Item item = form.Items.Item( "mtx_" + (form.PaneLevel) );
        Matrix mtx = (Matrix)item.Specific;

        int selRow = mtx.GetNextSelectedRow(0,BoOrderType.ot_SelectionOrder);
        if	(selRow == -1)
          return;
        mtx.DeleteRow(selRow);

        if (form.Mode != BoFormMode.fm_ADD_MODE)
          form.Mode = BoFormMode.fm_UPDATE_MODE;

        form.Freeze(false);
      }

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Tim,

I have just tried B1DE code (the same one you just show in precedent post) and it works fine for me.

Which B1 version are you working with?

Have you tried to create an addon with the Code Generator Wizard to see if it works for you? Just create a simple addon referencing your UDO with an automatically created form and just run it to see if the delete line button form works fine.

Regards

Trinidad.

Gianluigi
Product and Topic Expert
Product and Topic Expert
0 Kudos

Check B1DE AddOn wizard source code. It contains the code to delete a row

in a UDO form. It is available here on SDN under Business One SDK Tools.