How to group the editors in .NET MAUI DataForm (SfDataForm)?
The Syncfusion® .NET MAUI DataForm supports grouping the editors using either the Display attribute or the GenerateDataFormItem event with the GroupName property.
Using attributes:
Group the editors by setting the GroupName property of the Display attribute.
C#
public class DataFormModel { [Display(GroupName = "Name")] public string FirstName { get; set; } [Display(GroupName = "Name")] public string LastName { get; set; } [Display(GroupName = "Details")] public string Address { get; set; } [Display(GroupName = "Details")] public string City { get; set; } [Display(GroupName = "Details")] public string Country { get; set; } }
Using Event:
Grouping can also be achieved by setting the GroupName property using the GenerateDataFormItem event.
C#
private void OnGenerateDataFormItem(object sender, GenerateDataFormItemEventArgs e) { if (e.DataFormItem != null) { if (e.DataFormItem.FieldName == "FirstName" || e.DataFormItem.FieldName == "LastName") { e.DataFormItem.GroupName = "Name"; } else if (e.DataFormItem.FieldName == "Address" || e.DataFormItem.FieldName == "City" || e.DataFormItem.FieldName == "Country") { e.DataFormItem.GroupName = "Details"; } } }
Bind the DataFormModel property to the DataObject property of the SfDataForm.
XAML:
<dataForm:SfDataForm x:Name="dataForm" DataObject="{Binding DataFormModel}"> <dataForm:SfDataForm.BindingContext> <local:DataFormViewModel/> </dataForm:SfDataForm.BindingContext> <dataForm:SfDataForm.Behaviors> <local:DataFormBehavior/> </dataForm:SfDataForm.Behaviors> </dataForm:SfDataForm>
Download the complete sample on GitHub
Output:
Using Attribute
Using Event
Conclusion:
I hope you enjoyed learning how to group editors in .NET MAUI DataForm (SfDataForm).
Refer to our .NET MAUI DataForm feature tour page for 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 following comments 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!