1. Larry Peters
  2. PowerBuilder
  3. Monday, 4 July 2022 01:08 AM UTC

This sounds so trivial that I'm sure I'm experiencing a mental block, but:

In a datawindow column I wish to place an expression such that the column color is red (255) IF the value in row 5, column 2 is a particular value. (Note that row 5 is NOT relative, i.e. this is NOT the fifth row after the current row; it is row 5). What would the expression look like?


Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Monday, 4 July 2022 04:08 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Larry - I assume you will know the name of the second column object and you will place the background color expression in this column object. That being the case, I think that the expression:

If(GetRow() = 5 And your-column-name_here = 1234, RGB(255,0,0), RGB(255,255,255))

will set the color to red if the column contains the value 1234, but only in row 5, otherwise the color will be white.

Regards, John

There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 6 July 2022 01:58 AM UTC
  2. PowerBuilder
  3. # 1

No problem, Larry.

I've attached the exported source (zip'd, of course) of an exported DataWindow data object that mimics the data in your post. It already contains the data, so import it and assign the data object to a new DataWindow control.

In addition to the column header text, columns and data, it also contains a Computed Field named c_current_code. It's expression is very simple... it contains a string value. The value doesn't matter as long is it is not a value that will appear in the code (column1) column.

In the DataWindow control, place the following code in the Constructor event:

Long   ll_rowcount
String ls_code


ll_rowcount = This.RowCount()
If ll_rowcount > 0 Then
   ls_code = this.GetItemString(1,"code")
   ls_code = 'Junk'
End If

This.Object.c_current_code.Expression = "'"+ls_code+"'"

In the RowFocusChanged event, place this code:

String ls_code

ls_code = this.GetItemString(currentrow,"code")

This.Object.c_current_code.Expression = "'"+ls_code+"'"

The background color of the column objects use an expression to set the color to yellow if the value of the "code" column matches the value of the Computed Field, which is set initially and whenever row focus changes.

HTH, John

Attachments (1)
  1. Larry Peters
  2. Wednesday, 6 July 2022 22:12 PM UTC
Hi John,

Great trick and works fine.

Similar to my current technique except it is storing the code in a computed field in the datawindow rather than in a global variable.

  1. Helpful
There are no comments made yet.
Larry Peters Accepted Answer Pending Moderation
  1. Tuesday, 5 July 2022 23:46 PM UTC
  2. PowerBuilder
  3. # 2

Hi John,

As your answer obviously works I'm happy to accept it as the answer.

However, I did not properly articulate my need. I'll try again.

This is the effect I'm looking for. So long as my currentrow is within the range where the currentrow.Column_1 is 'active' the background is yellow (Column_1 is 'BDD').

When I move to another row where the Column_1 has changed I expect the new range becomes yellow (Column_1 is 'DPD'):

This is currently being done by saving the Column_1 value to a global variable and then testing that global variable in the datawindow backgroundcolor expression. Too clumsy.

I would like to limit the code to datawindow expressions without using the global variable. In other word I would like to know how to access the Column_1 value in the current row to influence the background color for all rows which have that value in Column_1 (rows may not be sorted).

Thanks anyway,


There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 4 July 2022 20:09 PM UTC
  2. PowerBuilder
  3. # 3

The answer I supplied works fine. I tested it in a drop-down DataWindow data object. Here's the expression for the background color of the second visible column object (named "truetypefont_status"):

   If(GetRow() = 5 And LookUpDisplay(truetypefont_status) = 'Unknown', RGB(255,0,0), RGB(255,255,255))

and here are two examples illustrating the results:

With different data in the second column of row 5:

Note the "GetRow()" function in this case is a DataWindow expression function, not the DataWindow method. The value it returns depends on the band. For more information, look at PB Help for the topic named "GetRow (DataWindow expression function)".

There are no comments made yet.
Arthur Hefti Accepted Answer Pending Moderation
  1. Monday, 4 July 2022 18:06 PM UTC
  2. PowerBuilder
  3. # 4


I don't think you can do that with an expression as you're referencing a row/column. My suggestion is doing this with a modify in the retrieveend and the itemchanged event.

I would create a computed column lets say backcolor and set the expression to value of white or transparent color. This computed I would assign as background color expression to all columns that should change the color. Now in the events modify the expression to the appropriate color.


There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Monday, 4 July 2022 15:04 PM UTC
  2. PowerBuilder
  3. # 5

not relevant to your question:

also, if you want to reference a value in a specific row that is not the current row, you can use [] as the offset to the current row.  (these are not absolute row numbers, but offsets to the current row)

mycolumn = current row

mycolumn[1] = row after current row

mycolumn[-1] = prior row


so, if you want to change the color in the current row based on the value of the next row (say if you are highlighting duplicates), you use this technique


IMO this is not well documented yet is extremely useful.  

  1. John Fauss
  2. Monday, 4 July 2022 19:54 PM UTC
That's cool, Mike! I did not know about this. Thanks for sharing!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1

There are no replies made for this question yet.
However, you are not allowed to reply to this question.