Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > How to add Form Items programmatically

Forum

Search UsersRules
How to add Form Items programmatically
#1
Active user
Points:: 0
Joined:: Jul 28, 2015

Hi everyone;

I have to add Form Items via code. In our configuration we have to develop creating survey as dynamic module. And I have to add Form Item as programmatically I mean via code. How can I do that? How can I add Form Item via code?

Profile
#2
Guest
Points::
Joined::

Hello, Mehmet Tuğrul SARIÇİÇEK

Please see following examples:
Add a button to a form without of changing that form
How to create print forms dynamically

Profile
#3
Active user
Points:: 0
Joined:: Nov 19, 2012

Hi Mehmet Tuğrul SARIÇİÇEK,

Here is an example how to dynamically create buttons and input fields:

Code
   //Add new command and button
   ButtonCode = "NewButton";
   
   FormCommand = ThisForm.Commands.Add(ButtonCode);
   FormCommand.Action = "ButtonClick";
   FormCommand.Title = "ButtonClick";
   
   NewButton = Items.Add(ButtonCode, Type("FormButton"));
   NewButton.Type             = FormButtonType.UsualButton;
   NewButton.CommandName       = ButtonCode;
   NewButton.Title          = "Push me!";
   NewButton.Picture          = PictureLib.AddToFavorites; 
   NewButton.Representation    = ButtonRepresentation.PictureAndText;
   
   //add new input fields - checkbox and text input
   NewAttributes = New Array;
   NewAttributes.Add(New Structure("FieldCode,Type,Boolean", "FieldBoolean", New TypeDescription("Boolean"), True));
   NewAttributes.Add(New Structure("FieldCode,Type,Boolean", "FieldString", New TypeDescription("String"), False));
   
   AddDetails = New Array;
   
   For Each Page In NewAttributes Do
            
      Attribute = New FormAttribute(Page.FieldCode, Page.Type, , Page.FieldCode, True);
      
      AddDetails.Add(Attribute);
      
   EndDo;
   
   ThisForm.ChangeAttributes(AddDetails);

   For Each Page In NewAttributes Do
      
      Control = Items.Add(Page.FieldCode, Type("FormField"));
      Control.Type = ?(Page.Boolean, FormFieldType.CheckBoxField, FormFieldType.InputField);
      Control.DataPath = Page.FieldCode;
      
   EndDo;

Profile
#4
Active user
Points:: 0
Joined:: Jul 28, 2015

Hi Aleksey Bochkov,

Thank you so much

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.