Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

matrix addrow

Hi

I have a simple form. As soon as i click Addrow button i need to add a row in the matrix. I have opened the form first time and clicked addrow buttond a new row is getting added into the matrix. Now i have clicked the cancel button in the form. And then i reopened the form again when i click addrow button 2 new rows are getting added. but i need to add only single row.

Please let me know the solution. i have given the sample code for your reference.

Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

If (FormUID = "Frm_QTENT1") Then

If (pVal.Before_Action = False) Then

If (pVal.ItemUID = "Addrow") And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK) Then

Dim f As SAPbouiCOM.Form

Dim oMatrix As SAPbouiCOM.Matrix

f = SBO_Application.Forms.Item(FormUID)

oMatrix = f.Items.Item("mat1").Specific

f.DataSources.DBDataSources.Item(1).Clear()

oMatrix.AddRow(1)

End If

End If

End If

End sub

You can also test . Just add a matrix to a form and then add one button. In the itemevent just past the code above and run the form. And then click addrow button

you can see a new row is added into the matrix. When cancel the form. And now open the form again now click add button only once. You can see 2 rows are getting added. The code what is pasted will be fired 2 wise .

Please let me know how can i solve this problem.

If any one able to solve this problem i will give full reward points

regards

Suresh

Former Member
Former Member replied

Hi Suresh!

i guess if you reopen your Form the third time there will be added 3 rows when you click the button

i guess the problem is that you have multiple instances of the class where your code is working. the first time you run your form you create the first instance and SAP B1 runs through your ItemEvent in that class. Only one ItemEvent, only one Add, only one Row.

then you close your Form and opened it again. There you create the second instance. When you now click on your addRow Button SAP B1 will find two instances with exactly the same ItemEvent..so SAP runs through the first instance (creates a row) and runs through the second instance(creates the second row)...so far..

what to do..

use modules instead of classes...

if not, then you have to cut the connection of the first instance from your Application-Object when you cancel...

try something like

Me.SBOApplication=Nothing

in the et_Form_Close Event...

hope it helps

Matthias

Message was edited by:

Matthias Bergen

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question