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

Empty group in a grouped list view

Is it possible for the SfListView to have a group that does not have any items on it? I know that the grouping of the items in the list is resolved based on a property name but I was wondering if there was a way to have a group but with no items on it.

3 Replies

DB Dinesh Babu Yadav Syncfusion Team May 27, 2017 04:41 AM UTC

Hi Gerard,  
Thank you for using Syncfusion products.  
In SfListView, we have grouped the items based on the underlying data bind to ItemsSource property and this is the actual behavior of SfListView. So in order to achieve your requirement “Displaying group headers only without items”, we have an workaround in the sample level by handing the QueryItemSize event and with AutoFitMode as “Height”. By defining the ItemsSize as “0” and handling the event as e.Handled as “True” for the empty items, the group header is only visible. And by customizing the GroupHeaderTemplate, you can add the items by tapping on the customized group header template and after the item is added based on the content the size for the item is set. For your reference, we have attached the sample and you can download the same from the below link.  
Please let us know if you require further assistance.  
Dinesh Babu Yadav 

JE Jean-Luc June 22, 2020 01:23 PM UTC

Works with Android, but not with UWP. When an item is dragged and dropped in another group, the source group shows the dummy item in its full size. Any solution to fix the problem?  
Thank you.

LN Lakshmi Natarajan Syncfusion Team June 23, 2020 11:34 AM UTC

Hi Jean, 
Thank you for using Syncfusion products. 
We have checked the reported query “Issue with empty group in ListView” from our end. We would like to inform you that we could reproduce the reported scenario when drag and drop an item to another group. The basic idea of empty grouping is we create an empty item with size as zero. In this case, the dummy item is still maintained in the collection. So, we need to remove the dummy items from the collection once we populate items at run time. Please refer the following code snippets to overcome the reported scenario, 
In the Add button command, remove the dummy items from the collection. 
private void OnButtonTapped(object obj) 
    var groupresult = obj as GroupResult; 
    var random = new Random(); 
    var contact = new Contacts(CustomerNames[random.Next(0, CustomerNames.Count() - 1)], random.Next(100, 450).ToString() + "-" + random.Next(451, 962).ToString()); 
    contact.ContactImage = ImageSource.FromResource("ListViewXamarin.Images.Image" + random.Next(0,28) + ".png"); 
    contact.Group = groupresult.Key.ToString(); 
    foreach (var item in groupresult.Items) 
        if ((item as Contacts).ContactName == "") 
We have attached the tested sample in the following link, 
You can also refer to the following document regarding the same from the following link, 
Please check the sample and let us know if you need further assisitance. 
Lakshmi Natarajan 

Live Chat Icon For mobile
Up arrow icon