How to update the editor value in .NET MAUI DataForm?
In Syncfusion® .NET MAUI DataForm, you can update the value of one editor based on changes in another editor using the UpdateEditor method.
This can be achieved by implementing INotifyPropertyChanged in your model class and handling property changes in the behavior class of the data form.
C#:
Register the required editors and set up the data form in the behavior.
protected override void OnAttachedTo(ContentPage bindable) { base.OnAttachedTo(bindable); dataForm = bindable.FindByName<SfDataForm>("dataForm"); if (dataForm != null) { dataForm.DataObject = new DataFormModel(); dataForm.ItemsSourceProvider = new ItemSourceProvider(); dataForm.RegisterEditor("City", DataFormEditorType.ComboBox); dataForm.RegisterEditor("Country", DataFormEditorType.AutoComplete); dataForm.PropertyChanged += OnDataObjectPropertyChanged; dataForm.GenerateDataFormItem += OnGenerateDataFormItem; } }
In the OnPropertyChanged method, change the value of the Age and Eligibility fields based on the selected value of the BirthDate field using the UpdateEditor method.
C#:
private void OnDataObjectPropertyChanged(object sender, PropertyChangedEventArgs e) { if (dataForm.DataObject != null && dataForm.DataObject is DataFormModel dataObject) { dataObject.Age = DateTime.Now.Year - dataObject.BirthDate.Year; dataForm.UpdateEditor("Age"); if (dataObject.Age != null) { if (dataObject.Age >= 18) { dataObject.Eligibility = true; } else { dataObject.Eligibility = false; } dataForm.UpdateEditor("Eligibility"); } } }
Output:
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to update the editor value in .NET MAUI DataForm.
You can refer to our .NET MAUI DataForm feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataForm documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataForm and other .NET MAUI components.
Please let us know in the following comment section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!