1. Toan Nguyen
  2. PowerBuilder
  3. Thursday, 8 August 2024 01:24 AM UTC

Hello All,

I have a question on how to programmatically set property value for the datawindow's columns.

In my application's window, I have a dropdown of colors and based on user's selection, I want to set the text color for all the columns in the datawindow to the picked color.

Is there an easy way to loop through all the columns in the datawindow and set the color property to a value? 

I want to avoid doing this if possible:

dw_1.object.column_1.color = RGB(0,0,128); dw_1.object.column_2.color = RGB(0,0,128); ... dw_1.object.column_n.color = RGB(0,0,128);

I want to be able to write the scripts like below:

integer li_column_ct, i

li_column_ct = integer(dw_1.Object.DataWindow.Column.Count)

For i = 1 to li_column_ct

dw_1.object.[i].color = RGB(0,0,128) // Referencing the columns by number???

Next 

Thanks for your help in advance!

Regards,

Toan

 

 

 

 

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 8 August 2024 04:44 AM UTC
  2. PowerBuilder
  3. # Permalink

H Toan,

instead of using dot notation you can use the Modify function. It supports the modification of columns by number:

dw_1.Modify ("#" + string (i) + ".color='" + string (rgb(0, 0, 128)) + "'")

 

If you do that in this way you have to keep in mind:

  • Datawindow.Column.Count is the number of the columns selected from the database or defined in column specifications. But it is possible that there is no column object for a datawindow column. In tis case if you try to modify the column object properties the Modify function will fail and the return value is an error message. (BTW: dot notation will throw an exception in this case)
  • It is also possible to insert more than one column object for the same column in a datawindow. In this case a Modify that specifies the column by number will only change one of the column objects (if I remember right it is the first in the object list).

 

A way to avoid such problems is to loop through Datawindow.Objects . It lists tab separated all objects (also texts, lines, ...) so you have to parse the list and also check for each object if it is a column (objectname.type). Because of this it is slower.

HTH,

René

 

Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Thursday, 8 August 2024 14:26 PM UTC
  2. PowerBuilder
  3. # 1

Hi Toan,

I see you've already resolved this but there is another other way to do it without having to cycle through all the objects in the datawindow object, which presents challenges, such as being slower, as René described:

Create a calculated field with just a value of 0 and place it in the header (you don't need it on each row), call it something like "cf_column_colour", and uncheck the Visible property. Then set the Font Text Color expression for each column to be a formula based on this calculated field, but simply insert the calculated field name.

When you want to change the colour at runtime, change the value. Since you can't use SetItemNumber() as it's a calculated column, you'll have to use Modify() and change its Expression value. Once you've changed the expression, call the datawindow.SetRedraw(True) method to refresh the display.

HTH...regards,

Mark

Comment
  1. René Ullrich
  2. Friday, 9 August 2024 04:24 AM UTC
Very smart!
  1. Helpful
  1. Mark Goldsmith
  2. Friday, 9 August 2024 14:03 PM UTC
Thanks René!
  1. Helpful
There are no comments made yet.
Toan Nguyen Accepted Answer Pending Moderation
  1. Thursday, 8 August 2024 12:48 PM UTC
  2. PowerBuilder
  3. # 2

Hi Rene,

Thank you for the solution and helpful suggestions!

Toan

Comment
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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.