To create a listview with an image, caption, and subtext in Delphi FMX, you can use the TListView control and set its ItemAppearance.ItemHeight property to a value larger than the default to make room for the subtext. Then, you can add items to the listview by creating TListViewItem objects and setting their properties.
Here is some sample code that demonstrates how to create a listview with an image, caption, and subtext in Delphi FMX;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
uses FMX.ImgList, FMX.ListView, FMX.ListView.Types; procedure TForm1.FormCreate(Sender TObject); var ImageList TImageList; ListView TListView; ListViewItem TListViewItem; begin //Create an image list ImageList = TImageList.Create(Self); ImageList.Width = 32; ImageList.Height = 32; ImageList.Add(‘CMyImagesImage1.bmp’); ImageList.Add(‘CMyImagesImage2.bmp’); ImageList.Add(‘CMyImagesImage3.bmp’); //Create a listview ListView = TListView.Create(Self); ListView.Parent = Self; ListView.Align = TAlignLayout.Client; ListView.ItemAppearance.ItemHeight = 64; Make room for the subtext ListView.ItemAppearanceObjects.ItemObjects.Image.ImageList = ImageList; //Add columns to the listview ListView.AddObject(TListViewHeader.Create(ListView)); ListView.AddObject(TListViewHeader.Create(ListView)); //Add items to the listview ListViewItem = TListViewItem.Create(ListView); ListViewItem.Text = ‘Item 1’; ListViewItem.Detail = ‘Subitem 1’; ListViewItem.ImageIndex = 0; ListView.AddObject(ListViewItem); ListViewItem = TListViewItem.Create(ListView); ListViewItem.Text = ‘Item 2’; ListViewItem.Detail = ‘Subitem 2’; ListViewItem.ImageIndex = 1; ListView.AddObject(ListViewItem); ListViewItem = TListViewItem.Create(ListView); ListViewItem.Text = ‘Item 3’; ListViewItem.Detail = ‘Subitem 3’; ListViewItem.ImageIndex = 2; ListView.AddObject(ListViewItem); end; |
This code creates an image list with three images, creates a listview and sets its ItemAppearance.ItemHeight property to a larger value to make room for the subtext, and then adds three items to the listview, each with a caption (stored in the Text property), subtext (stored in the Detail property), and an image from the image list.
Leave a Reply