Jump to content


Row Color depending on a field value


  • Please log in to reply
3 replies to this topic

#1 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 125 posts

Posted 29 November 2010 - 11:21 PM

Hello,

converting from TSMDBGrid. Found a few samples in respect to painting a row in a particular color depending on a field value, but all of them access the field value per index.

I have a field called OPERATION. Depending on the value of that field, the other columns for this particular row should be painted in a different color. When using the CellColoring event, how do I access the field value of a particular field by it's underlaying TDataSet field name.

Thanks,
Thomas


Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 6,686 posts
  • Gender:Male

Posted 30 November 2010 - 01:55 AM

Hello Thomas,

You may access to Column[x].Field property.

This property represents a Field of currently active record.
CODE
var
  Field: TField;
begin
  Field := NextDBGrid1.Columns[ACol].Field;
  if Field.AsInteger = 4 then CellColor := clRed;


Best regards
boki@bergsoft.net
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.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.

#3 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 125 posts

Posted 30 November 2010 - 10:03 AM

Hello Boki,

I know that example, the thing is, I can't access the field/column by a numeric index. I need to access the field/column by its underlaying database table field name.

Thanks,
Thomas
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 6,686 posts
  • Gender:Male

Posted 30 November 2010 - 08:30 PM

Hello Thomas,

There is a property for accessing column by it's name:

CODE
NextGrid1.ColumnByName['colname'].Width


But I am not sure that this is what you need.

Best regards

boki@bergsoft.net
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.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