How to load the complex type property values in the Autocomplete Editor in the .NET MAUI DataForm (SfDataForm)?
The Syncfusion® .NET MAUI DataForm (SfDataForm) supports loading complex types of property values in the Autocomplete Editor. Follow the steps below to implement this functionality.
C#:
Create a class with complex properties.
public class ComplexModel
{
public string Name { get; set; }
public int DepartmentID { get; set; }
}
C#:
Create a method that provides a list of ComplexModel objects for the Autocomplete editor.
public object GetSource(string sourceName)
{
if(sourceName == "Department")
{
List<ComplexModel> departmentDetails = new List<ComplexModel>();
departmentDetails.Add(new ComplexModel() { Name = "Development", DepartmentID = 101 });
departmentDetails.Add(new ComplexModel() { Name = "HR", DepartmentID = 102 });
departmentDetails.Add(new ComplexModel() { Name = "Network", DepartmentID = 103 });
departmentDetails.Add(new ComplexModel() { Name = "Testing", DepartmentID = 104 });
return departmentDetails;
}
return new List<string>();
}
C#:
Attach the GenerateDataFormItem event handler and register the Autocomplete Editor.
protected override void OnAttachedTo(SfDataForm dataForm)
{
base.OnAttachedTo(dataForm);
if (dataForm != null )
{
dataForm.ItemsSourceProvider = new ItemSourceProvider();
dataForm.RegisterEditor("Department", DataFormEditorType.AutoComplete);
dataForm.GenerateDataFormItem += OnGenerateDataFormItem;
}
}
C#:
Implement the OnGenerateDataFormItem event to set the DisplayMemberPath and SelectedValuePath properties.
private void OnGenerateDataFormItem(object sender, GenerateDataFormItemEventArgs e)
{
if (e.DataFormItem!= null)
{
if (e.DataFormItem != null && e.DataFormItem.FieldName == "Department" && e.DataFormItem is DataFormComboBoxItem comboBoxItem)
{
comboBoxItem.DisplayMemberPath = "Name";
comboBoxItem.SelectedValuePath = "DepartmentID";
}
}
}
Output:
Conclusion:
I hope you enjoyed learning how to load the complex type of property values in the Autocomplete Editor in .NET MAUI DataForm (SfDataForm).
Refer to our .NET MAUI DataForm feature tour page to learn about its other groundbreaking feature representations. You can also 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 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!