DataWindow Script Techniques
How do I set a property for an entire column?
Modify(”shft_id.visible = 0″)
Modify(”shft_desc.protect = 1″)
How many rows selected?
Li_select_count = integer(dw_1.Describe(“Evaluate(‘Sum(if(IsSelected (), 1, 0))’, 0)”))
How do I check the name of the DataWindow?
adw_current.ClassName() = ‘dw_handwork_finishing’
Putting a Help button on a DataWindow dialog box
DataWindow dialog boxes, such as the ones which may come up for Sort( ) and Filter( ) after the Setxxx is passed a string variable with a Null value, can have a Help button appear. For details see 14-8 of the Mastering DataWindows 6.0 book.
How do I dynamically create and destroy bit maps in a datawindow?
You can dynamically create and destroy objects (such as text, bitmaps, and graphic objects) in a DataWindow object using CREATE and DESTROY requests as part of the Modify() function
This statement adds a bitmap named Logo to the header area for group level 1 in the DataWindow object:
Dw_1.Modify(“CREATE bitmap(band=header.1 “ &
+ “x=’1985’ y=‘4’ height=’128’ width=’146’ “ &
+ “filename=’C: \PICS\LOGO.BMP’ name=logo “))
The following statement destroys a bitmap object named logo:
Dw_Modify(“DESTROY log”)
Smart Filter (way cool)
Outside the datawindow, a sle exists. Whatever the user enters into this field will filter the datawindow . Any columns which do not include the entered string are excluded.
1) Create a computed column on the datawindow called c_key. This will contain a string of all the columns you wish to include in the filter. Any numbers or dates need to be converted to strings.
2) Do whatever you need to do to make this computed column not visible to the user
3) Add a single line edit with the following user event mapped to pbm_keyup
////////////////////////////////////////////////////////////////////////////// // Event: sle_filter:ue_keyup (pbm_keyup) // ////////////////////////////////////////////////////////////////////////////// string ls_Filter, ls_text ls_text = Upper(this.text) if ls_text = "" then ls_filter = "" else ls_filter = 'match (c_key, "' + ls_text + '")' end if dw_1.SetFilter(ls_filter) dw_1.Filter()
In a datawindow, how do I have the “Enter” key work like a tab?
You will need to declare a user event
ue_ReturnAsTab pbm_dwnprocessenter
In the ue_returnastab event code;
Send(Handle(this),256,9,Long(0,0)
Return 1
This is now part of the pfd_u_dw and the functionality is turned on by adding the following to the constructor event:
ib_enterastab = True
SetItem is too slow
When you have a need for speed:
Traditional method
Dw_example.InsertRow(0) Dw_example.SetItem(1, “StringCol1”, “Hello, There”) Dw_example.SetItem(1, “NumberCol1”, 100) Dw_example.SetItem(1, “NumberCol2”, 200) Dw_example.SetItem(1, “StringCol2”, “Hello, Again”)
Faster method
Dw_example.ImportString(“Hello, theres~t100~t200~tHello, Again”)
How do I make a datawindow read only?
Dw_1.object.DataWindow.ReadOnly = ‘yes’
Can you create an html form for a datawindow and datastore?
Yes, by using the GenerateHtmlForm function.
How do I coordinate the update of multiple DataWindows?
Update( ) will accept two parameters, AcceptText and ResetFlags. The default is True, True
Accept text True means that the edit control is sent to the DataWindow. DataWindow validation is performed.
ResetFlag = False will not reset the status flags. This must be done with the ResetUpdate( ) function.
Example:
IF dw_1.Update(True, False) = 1 THEN
IF dw_2.Updte( ) = 1 THE
COMMIT USING SQLCA
Dw_2.ResetUpdate( )
ELSE
ROLLBACK USING SQLCA
END IF
ELSE
ROLLBACK USING SQLCA
END IF
When a data entry fills an entire field, how do I make the cursor skip to the next field?
1. Auto Skip property of Edit Mask
When this box is checked on the Mask property sheet of the EditMask control, the user’s cursor will automatically skip to the next control in the tabbing order after entering all the characters allowed by the mask. If this box is not checked, the cursor will not skip automatically to the next control.
The AutoSkip property is a boolean value. This example enables automatic skipping to the next control.
em_1.AutoSkip = TRUE
2. The EditChanged Event
integer li_max_col_size, li_rc
string ls_col_name, ls_nextcol, ls_coldata
CHOOSE CASE dwo.name
CASE "system_no"
li_max_col_size = 3
ls_nextcol = "acct_code"
CASE "acct_code"
li_max_col_size = 3
ls_nextcol = "application_name"
CASE "dev_year"
li_max_col_size = 4
ls_nextcol = "last_application_upgrade_date"
CASE "app_fail_year"
li_max_col_size = 4
ls_nextcol = "shared_data_desc"
// CASE "last_application_upgrade_date"
// li_max_col_size =
CASE ELSE
Return 0
END CHOOSE
ls_col_name = dwo.name
GetItemString(row, ls_col_name)
IF Len(GetItemString(row, ls_col_name)) > 0 THEN Return
IF Len(data) >= li_max_col_size THEN
li_rc = this.AcceptText( )
IF li_rc = 1 THEN
li_rc = this.SetColumn(ls_nextcol)
IF li_rc = -1 THEN
MessageBox("edit changed event”, “Unknown column ~"" + ls_nextcol + "~"")
END IF
ELSE
Return 0
END IF
END IF
I get the following Run Time Error: A PowerBuilder message box “Datawindow Error”, “Value Required For This Item”
I have a hh:mm editmask on a a datetime field, when I update the time, it sets the Date part to 01/01/2000
You need to find the correct date value through some other means, parse the new time from the data argument and glue the two together.
8 Comments »
Leave a comment
-
Archives
- May 2009 (1)
- March 2009 (1)
- January 2009 (2)
- December 2008 (1)
- November 2008 (2)
- September 2008 (1)
- August 2008 (1)
- July 2008 (24)
- June 2008 (22)
- May 2008 (69)
- April 2008 (25)
-
Categories
-
RSS
Entries RSS
Comments RSS
good day!! Is there a powerscript/code that will protect a row with specific column in a datawindow?
Michael,
If I understand your comment right, one way to do this is to write an expression in the datawindow painter. If you want to lock down the whole row, you will need to write the same expression in each column. Something like
if (lock_ind = “Y”, 1, 0)
You probably want to use another expression to set the background color for each column as well.
how to get ports name (com & LPT ) in powerbuilder..thanks
hello,
Is there a way to disable/enable individual “cells” within a radiobutton datawindow control? For example, let’s say I set up a column with style type radiobuttons that has four entries in the code table. Based on criteria, I want to enable/disable the ability to select an individual button within the list of four. Thanks
Hi Eric,
I am not aware of any way to turn off individual rb items. Have you considered changing this to a dddw and filter out the invalid options? See this post for more on filtering dddw
If you want to keep the radio button look, you will have to add script to the itemchanged event and reject invalid changes there.
Hello,
In one of the datawindow that Im creating, the user will give a query. How to make a datawindow editable by the user so that he can give the input? I have used the code:
dwindowname.Modify(”DataWindow.QueryMode=’YES’”) with no use.
Thanks.
Hi. I’m trying to modify the color of text by rows. The problem is – the text will be one of 6 colors and that is a huge case statement that i don’t want to do on each field in the row. I’m trying to use the modify but its changing every row not just the one it should. Any help would be greatly appreiceated!!!
If each column will have the same datawindow expression in its text.color property, why don’t you move the logic to a global function. Then instead of having the huge datawindow expression, you call this global function instead.
Still a lot of pasting, but you have only one bit of code to maintain in case you need to make a change.