2

I am creating an addon and for that I have successfully connected DI and UI API. I am creating everything (forms, buttons, textbox, etc.) manually by code to learn as this is my first one. When I debug, I can see my form with all the fields I created. Here is the code for form creation.

  SAPbouiCOM.FormCreationParams oCreationParams = null;
  oCreationParams = ((SAPbouiCOM.FormCreationParams(SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)));
  oCreationParams.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Fixed;
  oCreationParams.UniqueID = "Form2";
  oForm = SBO_Application.Forms.AddEx(oCreationParams);


  oForm.Title = "Simple Form";
  oForm.Left = 417;
  oForm.Top = 520;
  oForm.ClientHeight = 610;
  oForm.ClientWidth = 770;

Here is how I create my button:

 SAPbouiCOM.Button oButton = null;
 oItem = oForm.Items.Add("Button1", SAPbouiCOM.BoFormItemTypes.it_BUTTON);
 oItem.Left = 6;
 oItem.Width = 65;
 oItem.Top = 51;
 oItem.Height = 19;
 oItem.Enabled = true;
 oButton = ((SAPbouiCOM.Button)(oItem.Specific));
 oButton.Caption = "Add";

The problem is when I try to add the values of textbox in database on button click event, I am not able to generate a button click event.

From my knowledge when we create a button from toolbox and use system form, it automatically initializes the button ON InitializeComponent() function and also creates a delegates pointing to button click event.

May I know how to achieve all these through code?

I tried to initialize button through my manual code and also created delegates pointing to a button click function but I was unable to achieve my result.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Ranu Vijay
  • 1,137
  • 9
  • 18

1 Answers1

1

Try adding a method that captures SAP B1 item events like this:

public void HandleItemEvent(ref SAPbouiCOM.ItemEvent pVal)
{ 
    if (pVal.BeforeAction == false && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "Button1")
    {
        // You code here
    }
}
Kinyanjui Kamau
  • 1,890
  • 10
  • 55
  • 95
  • Thank you for your response, i figured out that we have to manually create a item handler delegate and call the item event function. – Ranu Vijay Sep 16 '18 at 21:41