Search code examples
androidiosdelphifiremonkeydelphi-xe8

Set grouping on TListView


I am writing an app which contains an FMX.TListView component. I have manually build the list with a few items so it contains something in it.

So some items begin with the letter A, B, C and so on.

I was wondering how I go about grouping the items so they appear under alphabetical group?

Any help would be appreciated.

Thanks,


Solution

  • The trick is the alphabetical groups are just additional items that you need to add to the TListView. Suppose that you are about to add a few items that all begin with the letter 'A'. Before you add these items, do the following:

            Item := ListView.Items.Add;
            Item.Text := 'A';
            Item.Purpose := TListItemPurpose.Header;
    

    Now add the items that begin with the letter 'A' as you normally would. Repeat the above just prior to adding the next group.