We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dynamically Loading DataForm

I am trying to implement a dynamic form using the SFDataForm control with the DataObject bound to a view model containing an entire set of about 80 properties.  The idea is for a user to select a "Form" from a SFComboBox and have the DataForm regenerate and hide the items that don't exist on the selected form.  Each "form" is simply an object with list of the property names (out of the 80 possible properties on the view model) to be displayed by the DataForm.  

To accomplish this, I am trying to use the DataForm_AutoGeneratingDataFormItem event and cancel each item that isn't in the list of properties in the selected form.  It appears that the DataForm_AutoGeneratingDataFormItem event only fires during the initial rendering of the control.  Calling RefreshLayout doesn't seem to trigger the refresh.  Where am I going wrong?

Here's the relevant code:
        private void DataForm_AutoGeneratingDataFormItem(object sender,                                              Syncfusion.XForms.DataForm.AutoGeneratingDataFormItemEventArgs e)
        {

            if (e.DataFormItem.Name != null)
            {
                Debug.WriteLine(e.DataFormItem.Name);

                //Get a copy of the view model
                if (_vm == null)
                    _vm = (TrackingViewModel)this.BindingContext;


                //if the item being generated isn't in the list of fields for the selected report then don't create it    
                if (!_vm.SelectedForm.FormFields.Contains(e.DataFormItem.Name))
                    e.Cancel = true;

            }

        }


        private void SfComboBox_SelectionChanged(object sender, Syncfusion.XForms.ComboBox.SelectionChangedEventArgs e)
        {
          //User selected a different Form to display

            dataForm.RefreshLayout();

            
        }

1 Reply

AK Ajith Kumar Senthil Kumar Syncfusion Team October 3, 2019 06:45 AM UTC

Hi Gary Butler, 
 
Thank you for using Syncfusion products. 
 
Based on the provided information, your requirement of “Removing the data field displayed in the dataForm at runtime” in Xamarin.Forms. To achieve this, you should set refreshLayout flag to true and pass the argument as true in RefreshLayout method. It triggers DataForm_AutoGeneratingDataFormItem event for all the fields where you can cancel a data field item generation. 
 
Please refer the following code example for the same, 
 
[C#] 
        private void Combobox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
        { 
            this.dataForm.RefreshLayout(true); 
        } 
 
 
We have prepared sample based on your requirement, please find the sample by the following link. 
 
In the sample, as per your requirement we have cancelled the dataformItem in runtime in DataForm_AutoGeneratingDataFormItem. 
 
You can also refer our online user guide documentation regarding the same by the following link, 
 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Ajith 


Loader.
Live Chat Icon For mobile
Up arrow icon