Saturday 15 June 2013

delphi - Add icon to TListView -


I show some lines and I'm trying to put an icon in TListView Timest list , but it is not connected I have this code

  Testing with sListView2: = sListView2.Items.Add; exam. Caption: = sListbox2.Items [i]; Test.SubItems.Add (test '); Test.ImageIndex (ImageList1.AddIcon (1)); End; Can anyone tell me what I am doing?   

TImageList.ImageIndex is an integer, and you set it up correctly Is required, and you need to provide this a TIcon to call AddIcon .

If you already have this in TImageList , then set TListView.ImageIndex in the appropriate index of that image:

 Assign an image from the imagelist to the  // index test. Image index: = 1; // Second image in the image list   

Or, if you do not have an existing icon in TImageList and need to add it, then add and store it < Return value from Code> AddIcon :

  // Create a new imprint, load an icon from the disk file, and // add it to the imagelist and set it to the new icon Index TListView.ImageIndex // Ico: = TIcon.Create; Try Ico.LoadFromFile (SomeIconFileName); Test.ImageIndex: = ImageList1.Add (Ico); Eventually Ikko free; End;   

BTW, you can simplify your code a bit (be careful with with though!):

  sListView2 With .ems. Add captions start: = sListbox2.Items [i]; SubItems.Add (test '); Image index: = 1; End;    

No comments:

Post a Comment