We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Display Group Key in column

Thread ID:





149274 Nov 20,2019 11:28 AM UTC Nov 22,2019 03:01 AM UTC Xamarin.Forms 1
Tags: SfListView
Laerte Alexi
Asked On November 20, 2019 11:28 AM UTC

I need show my group key in column in my SfListView.

Please see the image attachment.

Attachment: GroupColumn_c36f11f0.zip

Gnana Priya Namasivayam [Syncfusion]
Replied On November 21, 2019 09:45 AM UTC

Hi Laerte, 
Thank you for using Syncfusion products. 
We have checked the reported query “Display group key values in a separate row” and You can achieve your requirement by adding groups keys in the separate layout like StackLayout or Grid in code behind and create key labels while loading listview as in the following so that Key’s will be generated only for the present groups. 
    <Grid > 
           <RowDefinition Height="*"/> 
            <syncfusion:SfListView  x:Name="listView" ItemSize="80" Grid.Row="0" 
                                    IsStickyGroupHeader="True" SelectionMode="None" 
                                   ItemsSource="{Binding contactsinfo}"> 
            <Grid Grid.Row="0" x:Name="LabelForGrid" HorizontalOptions="EndAndExpand" VerticalOptions="StartAndExpand"/> 
</ContentPage > 
public class Behavior : Behavior<ContentPage> 
        private Grid grid; 
        private Label label; 
        private Label previousLabel; 
        public SfListView ListView { get; private set; } 
        protected override void OnAttachedTo(ContentPage bindable) 
            ListView = bindable.FindByName<SfListView>("listView"); 
            grid = bindable.FindByName<Grid>("LabelForGrid"); 
            ListView.DataSource.GroupDescriptors.Add(new GroupDescriptor() 
                PropertyName = "ContactName", 
                KeySelector = (object obj1) => 
                    var item = (obj1 as Contacts); 
                    return item.ContactName[0].ToString(); 
            ListView.Loaded += ListView_Loaded;  
        private void ListView_Loaded(object sender, ListViewLoadedEventArgs e) 
            var groupcount = this.ListView.DataSource.Groups.Count; 
            for (int i = 0; i < groupcount; i++) 
                label = new Label();  //New labels created based on the group header key value 
                GroupResult group = ListView.DataSource.Groups[i]; 
                label.Text = group.Key.ToString(); 
                grid.Children.Add(label, 0, i); 
                var labelTapped = new TapGestureRecognizer() { Command = new Command<object>(OnTapped), CommandParameter = label }; 
        private void OnTapped(object obj) 
            if (previousLabel != null) 
                previousLabel.TextColor = Color.DimGray; 
            var label = obj as Label; 
            var text = label.Text; 
            label.TextColor = Color.Red; 
            for (int i = 0; i < ListView.DataSource.Groups.Count; i++) 
                var group = ListView.DataSource.Groups[i]; 
                if (group.Key == null) 
                    App.Current.MainPage.DisplayAlert("Message", "Group not available", "ok"); 
                if ((group.Key != null && group.Key.Equals(text))) 
                    ListView.LayoutManager.ScrollToRowIndex(ListView.DataSource.DisplayItems.IndexOf(group), true); 
            previousLabel = label; 
We have attached the model sample for your reference, please find the sample from the following link. 
Additionally, we would like to inform that you can also use Paging control to achieve your requirement. We had already published documentation about the Listview and Paging. Kindly refer to our documentation from the following link. 
We hope this helps. Please let us know if you need any further assistance. 
Gnana Priya N 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon