ComponentOne Xamarin.Mac
Controls / CollectionView / Features / Grouping
In This Topic
    Grouping
    In This Topic

    Grouping refers to combining rows based on column values. When grouping is applied to a grid, it automatically sorts the data, splits it into groups, and adds collapsible group rows above or below each group. Similarly, the ICollectionView interface supports grouping for data controls, such as grids. It implements GroupAsync method so that you can call the grouping operation in the collection view without having to cast to the specific interface. The GroupAsync method groups the collection view according to the specified group fields, group path, or group descriptions.

    The image below shows how TableView appears when grouping is applied.

    The following code examples demonstrate how to group the collection view according to the specified group fields.

    C#
    Copy Code
    using System;
    
    using AppKit;
    using Foundation;
    using C1.CollectionView;
    using C1.Mac.CollectionView;
    using System.Threading.Tasks;
    
    namespace C1CollectionViewTest
    {
        public partial class GroupingViewController : NSViewController
        {
            public GroupingViewController(IntPtr handle) : base(handle)
            {
                
            }
    
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                Load();
                // Do any additional setup after loading the view.
            }
    
            private async Task Load()
            {
                var source = new C1TableViewSource(TableView);
                source.ItemsSource = Customer.GetCustomerList(100);
                await source.CollectionView.GroupAsync("Country");
                TableView.Source = source;
            }
    
            public override NSObject RepresentedObject
            {
                get
                {
                    return base.RepresentedObject;
                }
                set
                {
                    base.RepresentedObject = value;
                    // Update the view, if already loaded.
                }
            }
        }
    }