Jump to content


Photo

How to set cell image based on data value?


  • Please log in to reply
2 replies to this topic

#1 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 22 August 2017 - 05:36 PM

I currently have a column set as DBIcon, using a TImageList as its source. The column is using index 1 of the TImageList as the default icon, and I clear the cell in Col.OnSetCell if another DBColumn doesn't contain a specific value.  Right now, I can only have on/off behavior, however, based on new requirements, I need to expand that behavior to include additional images.

 

I don't see an obvious way to change the cell image.

 

How can I set the image for a DBIcon column to other images in a TImageList at runtime?



#2 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 23 August 2017 - 05:17 PM

I figured this out. Basically, don't try to manipulate the DBIcon field in code. Use data to drive it.

 

Add a field to your dataset that represents the image index as it corresponds to the image index in the TImageList.  Bind this field to the DBIcon in the grid.

 

If you return 1, the image at index 1 in the TImageList will be shown.



#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 23 August 2017 - 06:14 PM

Hi,

Also you can take a look at GetValue. This event "feed" routine used for drawing icon. Most columns have this event.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users