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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamically Loading DataForm

Thread ID:

Created:

Updated:

Platform:

Replies:

148032 Oct 2,2019 07:58 PM UTC Oct 3,2019 06:45 AM UTC Xamarin.Forms 1
loading
Tags: SfDataForm
Gary Butler
Asked On October 2, 2019 07:58 PM UTC

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();

            
        }

Ajith Kumar Senthil Kumar [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon