More examples in the DataWindow painter and in code

These examples illustrate the difference between the format for a DataWindow expression specified in the DataWindow painter versus in code.

Border property The expression applied to the Border property of the salary_plus_benefits column displays a border around salaries over $60,000:

If(salary_plus_benefits > 60000, 1, 0)

This statement changes the expression in code:

dw_1.Object.salary_plus_benefits.Border = &

		"0 ~t If(salary_plus_benefits > 60000, 1, 0)"

Font.Weight property for a column To make out-of-state (not in Massachusetts) names and numbers bold in a phone list, apply this expression to the name and phone_number columns. The state column must be part of the data source, but it does not have to be displayed:

If(state = 'MA', 400, 700)

This statement changes the expression in code:

dw_1.Object.name.Font.Weight = &

		"700 ~t If(state = 'MA', 400, 700)"

dw_1.Object.phone_number.Font.Weight = &

		"700 ~t If(state = 'MA', 400, 700)"

Brush.Color property for a rectangle This expression, applied to a rectangle drawn around all the columns in a tabular report, causes alternate rows to be shaded (a graybar effect). Make sure the columns and computed fields have a transparent background. The expression Mod(GetRow( ), 2) = 1 distinguishes odd rows from even rows:

If(Mod(GetRow(), 2) = 1, 16777215, 15790320)

This statement changes the expression in code:

dw_1.Object.rectangle_1.Brush.Color = &

	"0 ~t If(Mod(GetRow(), 2) = 1, 16777215, 15790320)"

Brush.Color and Brush.Hatch properties for a rectangle To highlight employees whose review date is approaching, draw a rectangle behind the row. This expression for the rectangle’s Brush.Color property makes the rectangle light gray for employees for whom the month of the start date matches the current month or the next month:

If(month(start_date) = month(today())

or month(start_date) = month(today()) + 1

or (month(today()) = 12 and month(start_date) = 1),

12632256, 16777215)

A similar expression for the Brush.Hatch property makes the fill pattern of the rectangle Bdiagonal (1) for review dates that are approaching. Otherwise, the rectangle is transparent (7) so that it does not show:

If(month(start_date) = month(today())

or month(start_date) = month(today()) + 1

or (month(today()) = 12 and month(start_date) = 1),

1, 7)

You can also set the Pen.Color and Pen.Style properties to affect the outline of the rectangle.

If you wanted to change the Brush.Color property in code instead of setting it in the painter, the code would look like this:

dw_1.Object.rectangle_1.Brush.Color = &

	"'16777215 ~t " + &

	"If(month(start_date) = month(today()) " + &

	"or month(start_date) = month(today()) + 1 " + &

	"or (month(today()) = 12 " + &

	"and month(start_date) = 1), 12632256, 16777215)'"

Font.Height property for a rectangle This expression applied to the Font.Height property of a text control makes the text control in the first row of a DataWindow larger than it appears in other rows. Make sure the borders of the text control are large enough to accommodate the increased size:

If(GetRow() = 1, 500, 200)

This statement changes the expression for the text control t_desc in code:

dw_1.Object.t_desc.Font.Height = &

		"200 ~t If(GetRow() = 1, 500, 200)"

For more information

For more information about DataWindow expressions, see Chapter 1, “DataWindow Operators and Expressions.”