cancel
Showing results for 
Search instead for 
Did you mean: 

Adding an item but not finding it

Former Member
0 Kudos
71

Hi

I can add an button to a form (the count property reflects that too) but i don't find it afterwards in the items - collection (you can reproduce the behaviour with the following code and by opening the businesspartners - form)

Tried with form.update,refresh but no success

TIA

Philipp



If pval.FormTypeEx="134" Then
	If  pval.BeforeAction=False And pval.EventType=SAPbouiCOM.BoEventTypes.et_FORM_LOAD Then
	' Button platzieren
	oForm=SBO_Application.Forms.Item(pval.FormUID)
	oItem = oForm.Items.Add("kit_1",SAPBouiCOM.BoFormItemTypes.it_BUTTON)
	oItem.Left=5
	oItem.Top=5
	oItem.Height=100
	oItem.Width=100
	oItem.Specific.Caption="Lala"
				
	For Each oItem In oForm.Items
	   If oItem.UniqueID="kit_1" Then
	    	SBO_Application.MessageBox("Halleluia")
	   End If
        Next

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Philipp,

Don't Add the the item and in the asme routine try to find it.

1. Add it in a routine like on the form load.

2. Find it in another routine like on a item pressed (button click).

I've found this is one of the "features" of the UI API. In your example there is no need to "find" it after you've added it...

Former Member
0 Kudos

Hi Barend

Thanks for your suggestions i really appreciate them.My example was a simplified Version of the real usage (just to reproduce it). And there I really need to find it again.

Imagine a PutButton Sub which places dynamically a button on a system form by searching the free space itself.

Now when you call this sub more than once (when you wanna put more than 1 buton on a form) then you will ran into this issue.

Will open an SAP message.

Thanks Philipp

barend_morkel2
Active Contributor
0 Kudos

Ok,

Let's try this:

1. Add the item (using the item object)

2. Free the item object (ItemObj = nothing).

3. Call the garbage collecter (GC.Collect in VB .Net)

4. Then check if you can find your new item (after re-creating the item object)

Former Member
0 Kudos

Hi Barend

Thanks for the tip but it didn't work.

As a workaround i'm doing now:


oItem = oForm.Items.Add("K_DUMMY1",SAPBouiCOM.BoFormItemTypes.it_BUTTON)
oItem.Visible=False

After the real item and then it works.

Answers (1)

Answers (1)

Former Member
0 Kudos

More Details...

after adding another item it finds the first one.

hmm somebody an idea?


If pval.FormTypeEx="134" Then
	If  pval.BeforeAction=False And pval.EventType=SAPbouiCOM.BoEventTypes.et_FORM_LOAD Then
	' Button platzieren
	oForm=SBO_Application.Forms.Item(pval.FormUID)
	oItem = oForm.Items.Add("kit_1",SAPBouiCOM.BoFormItemTypes.it_BUTTON)
	oItem.Left=5
	oItem.Top=5
	oItem.Height=100
	oItem.Width=100
	oItem.Specific.Caption="Lala"

oItem = oForm.Items.Add("kit_2",SAPBouiCOM.BoFormItemTypes.it_BUTTON)
oItem.Left=110
oItem.Top=5
oItem.Height=100
oItem.Width=100
oItem.Specific.Caption="Lala2"

				
	For Each oItem In oForm.Items
	   If oItem.UniqueID="kit_1" Then
	    	SBO_Application.MessageBox("Halleluia")
	   End If
        Next