cancel
Showing results for 
Search instead for 
Did you mean: 

Code Help for Right Click Add Row and Delete Row

Former Member
0 Kudos

Experts,

Can we write Code for matix so that like in std B1, right click Add row and delete row will be thre

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Refer This..........

[;

[;

[;

[;

[;

[;

Thanks

Shafi

Former Member
0 Kudos

I have written like below

Case "DeleteRow"

Try

Dim omatrix As SAPbouiCOM.Matrix

omatrix = objform.Items.Item("mtx_0").Specific

If omatrix.RowCount > 0 Then

Dim rows As Integer = omatrix.RowCount

For i As Integer = 1 To rows

If omatrix.IsRowSelected(i) = True Then

Dim result As Integer

result = SBO_Appln.MessageBox("Do You Want to Delete This Row", 1, "Yes", "Cancel")

If result = 1 Then

omatrix.DeleteRow(i)

objform.Mode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE

Exit For

End If

End If

Next

End If

Catch ex As Exception

SBO_Appln.MessageBox(ex.Message)

End Try

It is working now till deleting row and updating document, But...

After deleting, the row numbers are coming odd.

not insequential manner. please help

former_member689126
Active Contributor
0 Kudos

For delete row try this code

If _form.Mode <> BoFormMode.fm_FIND_MODE Then

                    Dim oMatrix As SAPbouiCOM.Matrix = _form.Items.Item(_matrixUID).Specific
                    Dim selRow As Integer = oMatrix.GetNextSelectedRow(0, BoOrderType.ot_SelectionOrder)
                    If selRow = -1 Then
                        B1Connections.theAppl.SetStatusBarMessage("Select a row to delete. ", BoMessageTime.bmt_Short, True)
                    Else
                        oMatrix.DeleteRow(selRow)
                         If _form.Mode <> BoFormMode.fm_ADD_MODE Then _form.Mode = BoFormMode.fm_UPDATE_MODE 
                    End If
                  
                End If

Regards

Arun

Former Member
0 Kudos

I can see row getting deleted, but after that,

row numbers are coming like

1

6

7

15

20

but i want like

1

2

3

4

5

former_member689126
Active Contributor
0 Kudos

Hi

Is your row number column is binbed with any data source ?

Regards

Arun

Former Member
0 Kudos

Yes it is bound with LineId field of UDT

Former Member
0 Kudos

Please suggest

Former Member
0 Kudos

Any Suggestions Experts?

former_member689126
Active Contributor

Hi shrutisapsen

after adding or deleting row try this code to reassign the row nos

With form.DataSources.DBDataSources.Item("@TABLE") '@TABLE is the name of the DBDataSource the form's connect to 
        .clear()
        matrix.FlushToDataSource()
        For iRow = 0 To .Size - 1
             .SetValue("U_RowNo", iRow, (iRow + 1).ToString) 'U_RowNo  is the db field binded with your row no column
        Next
 End With
 matrix.LoadFromDataSource()

Hope this helps you

Regards

Arun

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

For Delete Row U need to write this code

Try This.......


'WRITE IN MENU EVENT 

if pval.menuid='delrow' and pval.beforeaction=false then
Try
                    Dim omatrix As SAPbouiCOM.Matrix
                    oform = sbo_application.Forms.Item(FormUID)
                    omatrix = oform.Items.Item("mat_emp").Specific
                    If omatrix.RowCount > 0 Then
                        For i As Integer = 1 To omatrix.RowCount
                            If omatrix.IsRowSelected(i) = True Then
                                Dim result As Integer
                                result = sbo_application.MessageBox("Do You Want to Delete This Row", 1, "OK", "Cancel")
                                If result = 1 Then
                                    omatrix.DeleteRow(i)
                                End If
                            End If
                        Next
                    End If
                Catch ex As Exception
                    sbo_application.MessageBox(ex.Message)
                End Try
end if 

Thanks

Shafi

Former Member
0 Kudos

Row Invalid Index error coming , and it is not coming in Update mode also, And if i open the screen again, it shows again as if not deleted

And if i want to delete from among other rows, will it show like std B1 forms as if no.2 is deleted, so n0.3 row shifted up to no.2

Former Member
0 Kudos

Hi,

If You are using the Matrix With UDO then it will Come Automatically

If You are using the Non-UDO form then u need to try the beloc code

Try This.......


'WRITE THIS CODE IN RIGHT CLICK EVENT
 If eventInfo.FormUID = "sample" Then
            If (eventInfo.BeforeAction = True) Then
                Dim oMenuItem As SAPbouiCOM.MenuItem
                Dim oMenus As SAPbouiCOM.Menus
                Try
                    Dim oCreationPackage As SAPbouiCOM.MenuCreationParams
                    oCreationPackage = sbo_application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)

                    oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
                    oCreationPackage.UniqueID = "OnlyOnRC"
                    oCreationPackage.String = "AddRow"
                    oCreationPackage.Enabled = True

                    oMenuItem = sbo_application.Menus.Item("1280") 'Data'
                    oMenus = oMenuItem.SubMenus
                    oMenus.AddEx(oCreationPackage)

                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            Else
                Dim oMenuItem As SAPbouiCOM.MenuItem
                Dim oMenus As SAPbouiCOM.Menus

                Try
                    sbo_application.Menus.RemoveEx("OnlyOnRC")

                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try

            End If
        End If

The Above code Creates the Add Menu when u right click

U need to write the logic for right click menu

Thanks

Shafi

Edited by: shafi_sunshine on Sep 14, 2011 8:31 AM

Former Member
0 Kudos

for delete row if i write "delete row" replacing "add row" will it work properly means will it del the row?

former_member689126
Active Contributor
0 Kudos

Hi

Yes but you have to write code for that first enable menus 1292 and 1293

oForm.EnableMenu("1292", True)
 oForm.EnableMenu("1293", True)

then catch the before menu click event and write code for delete row and add row and set bubbleevent =false

1292 - add row

1293 - delete row

Regards

Arun