To create a listview with an image, caption, and subtext in Delphi, you can use the TListView control and set its ViewStyle property to vsReport. Then, you can add items to the listview by creating TListItem 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;
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 Vcl.ImgList, Vcl.Controls, Vcl.ComCtrls; procedure TForm1.FormCreate(Sender TObject); var ImageList TImageList; ListView TListView; ListItem TListItem; 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 = alClient; ListView.ViewStyle = vsReport; ListView.SmallImages = ImageList; Add columns to the listview ListView.Columns.Add; ListView.Columns.Add; Add items to the listview ListItem = ListView.Items.Add; ListItem.Caption = ‘Item 1’; ListItem.SubItems.Add(‘Subitem 1’); ListItem.SubItems.Add(‘Subitem 2’); ListItem.ImageIndex = 0; ListItem = ListView.Items.Add; ListItem.Caption = ‘Item 2’; ListItem.SubItems.Add(‘Subitem 3’); ListItem.SubItems.Add(‘Subitem 4’); ListItem.ImageIndex = 1; ListItem = ListView.Items.Add; ListItem.Caption = ‘Item 3’; ListItem.SubItems.Add(‘Subitem 5’); ListItem.SubItems.Add(‘Subitem 6’); ListItem.ImageIndex = 2; end; |
This code creates an image list with three images, creates a listview with two columns and sets its ViewStyle property to vsReport, and then adds three items to the listview, each with a caption, two subitems, and an image from the image list.
Leave a Reply