1. Glenn Barber
  2. PowerBuilder
  3. Tuesday, 8 September 2020 20:41 PM UTC

Ive been building a application that compares snapshots of tables, and have the code down to isolate the changes - now I need to highlight the background of the changed cells in a grid datawindow.

I am flagging the changed columns by setting the item status to datamodified! on the columns that were changed.

Now I need to create a global function I can call from a datawindow expression for the background color (like gf_getitemstatus (row, col) ) which will get the Status 1 when modified.

My questions is I assume I can get the row value with getRow()  - how do I get the column number (ID) and return that as a number?   I imagine I can hardcode the column number but was looking for a general way.

 

 

Michael Kramer Accepted Answer Pending Moderation
  1. Tuesday, 8 September 2020 22:51 PM UTC
  2. PowerBuilder
  3. # 1

This code works for me demo:

// Validation expression for column = myName
f_check( GetRow( ), Long( Describe("myName.ID")) )

GLOBAL FUNCTION f_check(long row, long column) return Boolean
// Demo - always accept any value
MessageBox(string(row), string(column)
return true

Notice, GetRow( ) in DW expressions returns the row that calls the function.

Describe("<columnname>.ID") returns column's number as a string, so I convert to LONG to pass as numeric value.

 

HOWEVER,
I would consider writing scripts on the DataWindow control - or NVOs having direct access to the DataWindow control (like "services" attached to the DW control). There you have much more freedom in access to the complete API of the DataWindow control - and access to the DataWindow object including its API inside the control.

HTH /Michael

Comment
  1. Glenn Barber
  2. Wednesday, 9 September 2020 17:54 PM UTC
In your posted example you have the prefix as a -1 - curious if that does something different. BTW Thanks for all the help - once I really dug into your example, i was able to find my way through it.
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 9 September 2020 18:34 PM UTC
-1, hmm can't remember setting that. The default value is what you type in the field of the attribute, but once there's an expression, the default should be ignored anyway.

you're welcome.
  1. Helpful
  1. Michael Kramer
  2. Wednesday, 9 September 2020 18:41 PM UTC
Format is <Default-value><TAB><Expression>

Default-value "wins" when Expression can't compute for whatever reason.

When your expression uses IF or CASE the ELSE-expression usually ends up being the fallback value (aka. default). Sometimes that ELSE-expression cannot compute - in that case the initial Default-value takes effect.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 9 September 2020 04:46 AM UTC
  2. PowerBuilder
  3. # 2

Hi Glenn,

I now see what your problem is. We can use "GetRow()" but there's no "GetColumnName()". Sorry for the advice on "@col" without actually trying.

 So here's what I came up with:

You have a global function which receives a rownumber (long) and a columnName (string).
Let's say it's called "gf_from_dw(long al_row, string as_col)"
In your column's attributes for background color, you initially set a dummy same expression for all columns:

gf_from_dw(getrow(), "[not_set_yet]").

Then somewhere, maybe in the constructor of the dw control,
you "loop through all of your columns", 
do a describe of the current expression ...
and replace the "[not_set_yet]" with the real column name...

To save time explaining, I've added Sample.zip.

Ignore almost everything on it, it was used for something else, just look at the button that says "none".

You'd still have to add some functionality which loops through all columns and not only the fixed "compute_1" as it does right now.

 regards,

hope it gives you an idea

Wow, almost time to "get up" :)

Attachments (1)
Comment
  1. Glenn Barber
  2. Wednesday, 9 September 2020 17:44 PM UTC
I ended up writing the code which auto populates the background color expression. - over all once I worked it out from the example it saved me a lot of time.
  1. Helpful
  1. Michael Kramer
  2. Wednesday, 9 September 2020 18:28 PM UTC
Happy to hear. Enjoy, /M
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 9 September 2020 18:32 PM UTC
Great new!
  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.