Show index of underlying collection

Hi support,
I want to show the index of the underlying collection of my list view (linear layout) in the first column of my data template.
The index has to start at 1 in order to show the ordering number of times which are displayed in the list.

Is there are predefined property I can use?

Regards,
Stephan


1 Reply

RM RiyasHameed MohamedAbdulKhader Syncfusion Team July 6, 2023 09:43 AM UTC

Hi Stephan,

SfListView does not have support for displaying the item index for each item. It can be achieved by customizing the ItemTemplate. We suggest you use a property in the model and set the index for each item in the viewmodel. Then, use a grid inside the ItemTemplate and bind the index property to the first column. We have also attached the code snippet for your reference.

CodeSnippet

public ContactsViewModel()

{

    contactsinfo = new ObservableCollection<Contacts>();

    Random r = new Random();

    for (int i = 0; i < CustomerNames.Count(); i++)

    {

     var contact = new Contacts();

     contact.ContactName = CustomerNames[i];

     contact.ContactNumber = ContactNumbers[i];

     contact.ContactType = ContactTypes[i % 2];

     contact.ItemIndex = i + 1;

     contactsinfo.Add(contact);

    }

}


Regards,
Riyas Hameed M


Loader.
Up arrow icon