Using Modify and SetProperty

Properties can also be modified using the Modify or SetProperty methods, but the syntax is more difficult to construct and prone to error.

The expression assigned to the TextColor property includes a default value. Nested quotes complicate the syntax, as in this C# example for Modify:

DW1.Modify("lname.TextColor = \"16777215 ~t If(bene_day_care = 'Y', 15790320, 16777215)\"");

This call to SetProperty achieves the same result:

DW1.SetProperty("emp_lname.Background.Color", "16777215 ~t If(bene_day_care = 'Y', 15790320, 16777215)");

This Visual Basic code achieves the same result using GraphicObject classes:

Dim colLastName As  _
   Sybase.DataWindow.GraphicObjectEditableColumncolLastName =  _
   CType(DW1.GetObjectByName("emp_lname"), _
   GraphicObjectEditableColumn)colLastName.BackgroundColor.Expression =  _
   "if(bene_day_care = 'Y', 15790320, 16777215)"

You can use both single and double quotes, but when you need to nest additional pairs of quotes, you use an escape character to identify inner nested pairs. For more information, see “Nested strings and special characters for DataWindow object properties”.

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 as opposed to Visual Basic code. The examples use a combination of Modify, SetProperty, and explicit access to GraphicObject properties.

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

If(salary > 60000, 1, 0)

This statement changes the expression in code using Modify:

DW1.Modify("salary.Border='0 ~t If(salary > 60000, 1, 0)'")

In this statement, salaryColumn is defined as a GraphicObjectColumn variable (or one of its descendants). You can get salaryColumn using a call to GetObjectByName or GetColumnObjectByNumber, or from the Gob element of the DataWindowControl’s ObjectUnderMouse structure:

salaryColumn.BorderStyle.Expression = "If (salary > 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 appearance of the name column in code:

DW1.SetProperty("name.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:

DW1.SetProperty("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.

To set the Brush.Color property in code:

DW1.SetProperty("rect1.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 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:

DW1.Modify("t_desc.Font.Height = '200 ~t If(GetRow() = 1, 500, 200)'")

For more information about DataWindow expressions, see the DataWindow Object Reference in the online help for DataWindow Designer.