How to load the complex type property values in the Combo Box Editor in the .NET MAUI DataForm (SfDataForm)?
The .NET MAUI DataForm (SfDataForm) control provides a versatile approach to editing complex data objects, including loading complex type property values in a Combo Box Editor. This guide illustrates how to achieve this functionality.
Create a model class that holds complex property types for use in the Combo Box Editor.
public class ComplexModel { public string Name { get; set; } public int DepartmentID { get; set; } }
Create a list of ComplexModel objects to load the values to the Department property in a Combo Box 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>(); }
Use the GenerateDataFormItem event handler to set the DisplayMemberPath and SelectedValuePath properties for the Combo Box Editor.
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"; } } }
Download the complete sample on GitHub
Output:
Conclusion:
I hope you enjoyed learning how to load complex type values into a Combo Box Editor within the .NET MAUI DataForm (SfDataForm).
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 comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!