Skip to main content

Adding Rows to the Bound DataGrid

On the Flow side, rows can be added to an associated DataGrid on the form by using the following code.

Because each row of the bound DataGrid is actually a form, before you add a row;

  • It is necessary to create the relevant form, fill in the data in it and save it and get the documentId value.
  • Then the row to be added to the DataGrid is prepared.
  • You then need to access the form that the DataGrid is in. From here, the DataGrid is accessed. The row is inserted. The data is merged. The form is saved.

Required Libraries

using Bimser.Synergy.Entities.Workflow.EventArguments; using System; using Bimser.Synergy.ServiceAPI; using Bimser.Synergy.ServiceAPI.Models.Authentication; using Bimser.Synergy.Entities.Shared.Business.Objects; using Newtonsoft.Json; using Bimser.CSP.Runtime.Common.Extensions; using System.Collections.Generic; using System.Threading.Tasks; using Bimser.Synergy.ServiceAPI.Models.Form;

Codes

Fill out a modal form FormInstance modalForm = GetFormInstance("projectName","modalformName",0). Result; modalForm.Controls["TextBox1"]. Value = "text"; modalForm.Controls["TextBox1"]. Text = "text"; var docid = modalForm.Save(). Result.DocumentId;

Add a new row to a DataGrid GridDataRow newRow = new GridDataRow { Cells = new List<GridDataRowCell> { new GridDataRowCell(docid,"RELATIONDOCUMENTID"), new GridDataRowCell(modalForm.Controls["TextBox1"]. Text,"TextBox1") } };

Accessing the form where the DataGrid is located FormInstance form = GetFormInstance("projectName","formName",Document1.DocumentId). Result; Control control =form. Controls["DataGrid1"]; The DataGrid data on the form is accessed GridData DataGrid1Data = GridData.FromControl(control); Cast from formdata to griddata for operations. DataGrid1Data.Rows.Add(newRow); Insertion of the row Merge data from a DataGrid with a legacy DataGrid FormData data = new FormData(); data. ControlValues.Add("DataGrid1", JsonConvert.SerializeObject(DataGrid1Data)); form. MergeData(data. ControlValues); form. Save();