Recent

Author Topic: Painting a Icon in ListView in vsreport mode  (Read 6627 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Painting a Icon in ListView in vsreport mode
« on: October 29, 2018, 12:16:01 pm »
Hi, I have a small application to show same information. See the image attached.
I will like use a Icon in "Tipo" column.
How can i do it?
I see this example in stackflow but I couldn't work it on Lazarus 2.0 RC1.
https://stackoverflow.com/questions/6612797/delphi-how-to-draw-small-icons-in-list-view-on-customdrawitem
Any Idea?
Thanks
« Last Edit: October 29, 2018, 01:12:19 pm by BlueIcaro »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Painting a Icon in ListView in vsreport mode
« Reply #1 on: October 29, 2018, 05:57:29 pm »
each TlistItem has a ImageIndex, StateIndex etc in it.

You can create a TImageList, add the images you want to it and tell the ListView/TreeVew to use that ImageList.

When you load your list, you need to specify the Image index for the listItem that is in that column.
 
 I believe you can specify two image indexes so that you can have a different image depending on the state (StateIndex)
The only true wisdom is knowing you know nothing

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Painting a Icon in ListView in vsreport mode
« Reply #2 on: November 02, 2018, 02:01:21 pm »
each TlistItem has a ImageIndex, StateIndex etc in it.

You can create a TImageList, add the images you want to it and tell the ListView/TreeVew to use that ImageList.

When you load your list, you need to specify the Image index for the listItem that is in that column.
 
 I believe you can specify two image indexes so that you can have a different image depending on the state (StateIndex)
How can I specify the image?, Using any event?
/BlueIcaro

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Painting a Icon in ListView in vsreport mode
« Reply #3 on: November 02, 2018, 02:50:24 pm »
you change the image index value of the node?

 The images are referenced from a TimageList. each image you put in will represent the state you want.

 so pick what ever event you want to use in the list and set the ImageIndex value in the Node to reflect the
the condition you would like..
 
  For example, if the row was locked you could put an image of a LOCK there , just change the ImageIndex..

 
  I don't know how else to explain it to you.

 P.S. node/Listitem

« Last Edit: November 02, 2018, 02:57:02 pm by jamie »
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Painting a Icon in ListView in vsreport mode
« Reply #4 on: November 02, 2018, 03:28:41 pm »
How can I specify the image?, Using any event?
/BlueIcaro

You can, indeed, use almost any event but the best place to do it is when you create/add the TListItem or, if needed, when a list item changes its state.

You should read the documentation for TListView and TListItem.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Painting a Icon in ListView in vsreport mode
« Reply #5 on: November 02, 2018, 04:12:17 pm »
you change the image index value of the node?

 The images are referenced from a TimageList. each image you put in will represent the state you want.

 so pick what ever event you want to use in the list and set the ImageIndex value in the Node to reflect the
the condition you would like..
 
  For example, if the row was locked you could put an image of a LOCK there , just change the ImageIndex..

 
  I don't know how else to explain it to you.

 P.S. node/Listitem

Thanks for your info. I did it as you say and it's works
I assigned a image to the item as I created.
Same thing like this:
Code: [Select]
     ListItem := Items.Add;
      Listitem.Caption := 'Name' + IntToStr(I);
      ListItem.ImageIndex := 1;
      Listitem.SubItems.Add('Second name');
/BlueIcaro

How can I specify the image?, Using any event?
/BlueIcaro

You can, indeed, use almost any event but the best place to do it is when you create/add the TListItem or, if needed, when a list item changes its state.

You should read the documentation for TListView and TListItem.
This example: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/ComCtrls_TCustomListView_Items.html was very useful for me

/BlueIcaro

 

TinyPortal © 2005-2018