cancel
Showing results for 
Search instead for 
Did you mean: 

manually creating events for button

former_member211473
Contributor
0 Kudos

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 uses 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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member416544
Participant
0 Kudos

Hi Ranu Vijay,

To handle the click events for User defined form's, in the form need to create 'SBO_Application_ItemEvent' event.

Find the below example code:

//User Defined Forms Button Click Events(SBO_Application_ItemEvent)

 public void SBO_Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
  {
    BubbleEvent = true;
    if (((pVal.ItemUID == "Button1") & (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) & (pVal.Before_Action == false)))
      {
     SBO_Application.MessageBox("Button clicked...!", 1, "Ok", "", "");
      AddFormDetails(); //here you can write business logic
      }
   }

and in your program.cs page need to add below line

var SimpleForm = new SimpleForm();
Application.SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler(SimpleForm.SBO_Application_ItemEvent);

Hopefully, the above code helps you.

Thanks,

Chenna.

former_member211473
Contributor
0 Kudos

You just cleared all my doubts, can you help with one more

 SAPbobsCOM.BusinessPartners oBp = null;
oBp = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
oBp.CardCode =  

How to set textbox value which i created manually as CardCode, because when i write oBp.CardCode = edittext1 (name of my textbox) it shows : edittext1 does not exist in current context.

Thank You

Ranu

former_member416544
Participant
0 Kudos

Hi Ranu Vijay,

Please have a look at the below mentioned code to get the textbox value.

private void AddFormDetails()
{
string CardCode= null;
SAPbouiCOM.Item oItem = null;
SAPbouiCOM.EditText oEdit = null;
SAPbouiCOM.Form oForm = SBO_Application.Forms.ActiveForm; //Active user-defined form

oItem = oForm.Items.Item("txtCardCode");
oEdit = ((SAPbouiCOM.EditText)(oItem.Specific));
CardCode = (oEdit.String);
oBp.CardCode=CardCode;
}

Thanks,

Chenna.

former_member416544
Participant
0 Kudos

Hi Ranu Vijay,

As your requirement is fulfilled, you may now close the thread with marking as a correction answer.

Thanks,

Chenna.

former_member211473
Contributor
0 Kudos

The textfield does not take the value when i enter in the form i created,

when i manually set the value of field as -

oEdit.String = "xyz";
CardCode = (oEdit.String);

I am able to add new Business Partner. with cardcode = xyz;

may i know what i missed now.

former_member416544
Participant
0 Kudos

Hi Ranu Vijay,

Can you please try with below mentioned code

oItem = oForm.Items.Item("txtCCode");
oEdit = ((SAPbouiCOM.EditText)(oItem.Specific));
(oEdit.String) = "C034139";
CardCode=(oEdit.String);

Thanks,

Chenna.

former_member211473
Contributor
0 Kudos

Thank you Mr Chenna for your valuable input. It was my mistake, i got my answer.

You made me understand a lot of valuable concept.

Kind Regards

Ranu Vijay

former_member416544
Participant
0 Kudos

You are most welcome Ranu Vijay

Regards,

Chenna

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Ranu Vijay,

Form creation is fine. Can you share your code you are using to handle the events?

Also, confirm whether the event et_Item_Pressed is getting executed or not?

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

former_member211473
Contributor
0 Kudos

Hi Ankit

Being a learner i was confused In so many ways, I also tried the way Mr Chenna told but somehow I missed something. if you can help me with one more doubt

SAPbobsCOM.BusinessPartners oBp = null;
oBp = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
oBp.CardCode = 

Now here CardCode should be TextBox value which i created manually as in above example.

Can you just guide how to ?

Thank You

Ranu Vijay