Toggle Button
Displays rating stars. The stars size, color, and value are all dynamic which makes it a better solution than using images.
Function Parameters
f_pbus_togglebutton (unsignedlong ahdc, long ax, long ay, long awidth, long aheight, string atoggle, string atheme)
Argument |
Description |
ahdc |
Always pass GetPaintDC() in the DW Expression |
ax |
Always pass GetPaintRectX() in the DW Expression |
ay |
Always pass GetPaintRectY() in the DW Expression |
awidth |
Always pass GetPaintRectWidh() in the DW Expression |
aheight |
Always pass GetPaintRectHeight() in the DW Expression |
atoggle |
A value indicating an on or off position. The following values will be interpreted as on: "1", "TRUE", "YES", "Y", "ON". Anything else will be interpeted as off. If your On value does match one of these values, you can use a computed expression to convert your value. |
theme |
Pass, as a string, the color of the circle. Valid values are "BLUE", "OLIVE", "SILVER", "BLACK", "CLASSIC", "PINK", "DEEPBLUE", "PURPLE", "GREEN", "ORANGE", "RED" |
Implementation
This control is rendered in a computed field on your dataobject. Start by adding a computed field to your datawindow and give it the width and height that you want (note: a width of 146 and height of 72 is a good starting point for size). Add an expression to the computed field that will look like this:
Paint
(
if (f_pbus_togglebutton(GetPaintDC(),
GetPaintRectX(),
GetPaintRectY(),
GetPaintRectWidth(),
GetPaintRectHeight(),
employee_bene_health_ins,
"BLUE")
, "", "Error")
)
The employee_bene_health_ins in this example is a field on the datawindow. Change this value. You can use a column, computed field, or hard coded value.
Allow User to Toggle the Button
By default, the toggle button is display only. You can add code to your datawindow control to allow a user to toggle the button with the mouse. In the Clicked event of your datawndow, do something like this:
String ls_columnname
String ls_currvalue
//If one of our computed fields with the toggle button is clicked, get the corrisponding column name
CHOOSE CASE dwo.Name
CASE "cmp_healthinsurance"
ls_columnname = "employee_bene_health_ins"
CASE "cmp_lifeinsurance"
ls_columnname = "employee_bene_life_ins"
CASE "cmp_daycare"
ls_columnname = "employee_bene_day_care"
END CHOOSE
//If we found a column name, we can toggle the value
//The developer needs to do this manually because we don't know what on or off is
//The toggle button will interpret "Y", "Yes", "1", "On", "True" as being On values.
IF Len(Trim(ls_columnname)) > 0 THEN
ls_currvalue = Upper(THIS.GetItemString(row, ls_columnname))
//Change the current value, if it was Y, change it to N, if it was N change it to Y
IF ls_currvalue = "Y" THEN
ls_currvalue = "N"
ELSE
ls_currvalue = "Y"
END IF
THIS.SetItem(row, ls_columnname, ls_currvalue)
END IF
Previewing Your Rating Control
The toggle button control will not render in the painter portion of the datawindow painter. It will display in the preview section of the datawindow painter. To see the control in design time, open the preview panel in the datawindow painter and retrieve a row.
Copyright © 2021 Werysoft Inc.