cancel
Showing results for 
Search instead for 
Did you mean: 

Right Click event addrow and delete row..

Former Member
0 Kudos
402

Hi.. See the images..

i had put right click event  on the matrix s.no

and put some code on it ..add row and delete row.

add row is comming .. i am able to add the rows to the matrix..

but delete row is not comming..

one more imp thing is if i click on the s.no V_1 column

the below screens are comming every clikcing how can i prevent this one

my requirement is how to prevent these screen and

delete row is not comming..

i used this code...

  Private Sub sbo_app_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles sbo_app.MenuEvent

        Try

            If (pVal.MenuUID = "delrow" And pVal.BeforeAction = False) Then

                oform = sbo_app.Forms.Item("TT")

                omatrix = oform.Items.Item("16").Specific

                'omatrix.DeleteRow(1)

                Dim i As Integer

                For i = 1 To omatrix.RowCount

                    If omatrix.IsRowSelected(i) = True Then

                        omatrix.DeleteRow(i)

                        omatrix.add()

                    End If

                Next

            End If

        Catch ex As Exception

            sbo_app.MessageBox(ex.Message)

        End Try

        Try

            If (pVal.MenuUID = "ADDROW" And pVal.BeforeAction = False) Then

                oform = sbo_app.Forms.Item("TT")

                omatrix = oform.Items.Item("16").Specific

                'omatrix.DeleteRow(1)

                ' Dim i As Integer

                ' For i = 1 To omatrix.RowCount

                'If omatrix.IsRowSelected(i) = True Then

                omatrix.AddRow(1)

                'omatrix.add()

                'End If

                '  Next

            End If

        Catch ex As Exception

            sbo_app.MessageBox(ex.Message)

        End Try

---------------------------------------------------------------------------------------------------------

    Private Sub sbo_app_RightClickEvent(ByRef eventInfo As SAPbouiCOM.ContextMenuInfo, ByRef BubbleEvent As Boolean) Handles sbo_app.RightClickEvent

        If eventInfo.FormUID = "TT" And eventInfo.ColUID = "V_-1" Then

            If (eventInfo.BeforeAction = True) Then

                Dim oMenuItem As SAPbouiCOM.MenuItem

                Dim oMenus As SAPbouiCOM.Menus

                Try

                    Dim oCreationPackage As SAPbouiCOM.MenuCreationParams

                    oCreationPackage = sbo_app.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)

                    oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING

                    oCreationPackage.UniqueID = "delrow"

                    oCreationPackage.String = "Delete Row"

                    oCreationPackage.Enabled = True

                    oMenuItem = sbo_app.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_app.Menus.RemoveEx("delrow")

                Catch ex As Exception

                    MessageBox.Show(ex.Message)

                End Try

            End If

        End If

        If eventInfo.FormUID = "TT" And eventInfo.ColUID = "V_-1" Then

            If (eventInfo.BeforeAction = True) Then

                Dim oMenuItem As SAPbouiCOM.MenuItem

                Dim oMenus As SAPbouiCOM.Menus

                Try

                    Dim oCreationPackage As SAPbouiCOM.MenuCreationParams

                    oCreationPackage = sbo_app.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)

                    oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING

                    oCreationPackage.UniqueID = "ADDROW"

                    oCreationPackage.String = "ADD ROW"

                    oCreationPackage.Enabled = True

                    oMenuItem = sbo_app.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_app.Menus.RemoveEx("ADD ROW")

                Catch ex As Exception

                    MessageBox.Show(ex.Message)

                End Try

            End If

        End If

    End Sub

Accepted Solutions (0)

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Seenu,

You can try this... You need not to code anything or providing Unique Ids for anything. Just try this once. your both Error will be solved.

if (pVal.ItemUID == enControlName.mtrx && pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK && pVal.ColUID == "col_f" && pVal.FormMode != 3)

            {

                SAPbouiCOM.EditText oEdit = (SAPbouiCOM.EditText)m_SBO_Form.Items.Item(enControlName.Status).Specific;

                string str = oEdit.Value.Trim();

                if (str != "Close")

                {

                    m_SBO_Form.EnableMenu("1293", true);

                    m_SBO_Form.EnableMenu("1292", true);

                }               

            }

This will enable the menu 'Add Row' & 'Delete Row'.

Code for Adding Row

case enSAPToolBarMenuUID.cst_AddRow:

                                {

                            皜       try

                                    {

                                        SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)this.m_SBO_Form.Items.Item(enControlName.mtrx).Specific;

                                        SAPbouiCOM.DBDataSource dbData = default(SAPbouiCOM.DBDataSource);

                                        dbData = (SAPbouiCOM.DBDataSource)m_SBO_Form.DataSources.DBDataSources.Item(1);

                                        m_SBO_Form.Freeze(true);

                                        if (oMatrix.VisualRowCount == 0)

                                        {

                                            dbData.Clear();

                                            oMatrix.AddRow(1, oMatrix.VisualRowCount);

                                            ((SAPbouiCOM.EditText)oMatrix.Columns.Item(enControlName.colQty).Cells.Item(oMatrix.VisualRowCount).Specific).Value = "";

                                        }

                                        else

                                        {

                                            EditText oEdit1 = (SAPbouiCOM.EditText)oMatrix.Columns.Item(enControlName.colItemCode).Cells.Item(oMatrix.VisualRowCount).Specific;

                                            if (oEdit1.Value.Trim().Length > 0)

                                            {

                                                dbData.Clear();

                                                oMatrix.AddRow(1, oMatrix.VisualRowCount);

                                                ((SAPbouiCOM.EditText)oMatrix.Columns.Item(enControlName.colQty).Cells.Item(oMatrix.VisualRowCount).Specific).Value = "";

                                            }

                                        }

                                    }

                                    catch (Exception ex)

                                    {

                                        Program.oMainSAPDI.ShowMessage(ex.Message, BoStatusBarMessageType.smt_Error);

                                    }

                                    finally

                                    {

                                        m_SBO_Form.Freeze(false);

                                    }

                                } break;

                        }

                    } break;

Hope it helps

Thanks