PB Data Window Setup operations

Source: Internet
Author: User
Tags rowcount

1 Make DataWindow column only append cannot modify
How to make the data in DataWindow can only append new records and cannot be modified, it is convenient to do this by using the Protect property of Column, the method is as follows:
Set the Protect property of each column to:
If (Isrownew (), 0, 1))
You can dynamically modify the Protect property in PowerScript:
Dw_1.modify ("Column_name_here. Protect= ' 1~tif (isrownew (), 0, 1) ' ")
This way, only newly appended records in the DataWindow can be modified, while other records are read-only.

2 How to implement automatic wrapping of columns in DataWindow
During the development of PowerBuilder applications, when we use DataWindow, we often encounter
The data to a column is too long to be displayed at the same time. If automatic horizontal scrolling is used, the operating
It's not easy enough to come. Here is a way to implement multi-line display of column data, that is, to implement column data from the
Dynamic folding lines. The following steps are:
1) Open this datawindow in DataWindow painter.
2) Double-click on the column where you want to set the auto-wrap row to open the Properties window for this column.
3) Select the Position tab and select the AutoSize Height multi box.
4) Select the Edit tab and uncheck the Auto Horz scroll multi box.
5) Click the OK button to save the changes.
6) Point Detail Band (that is, a gray long band with detail), right-click, select
Properties ... menu item.
7) Select the AutoSize height multi box.
8) Click the OK button to save the changes.
9) Save this DataWindow.
Attention:
The characters that are linked together (without punctuation or space), the system will be considered a word, not
The lines are automatically broken.

3 animating in the data window
To achieve animation, must have a timer, in the data window already has a timer, double-click the Data window will pop up the dialog box, in the timer interval defined value greater than 0 has a timer (can be accurate to milliseconds), with this timer can be implemented animation. For example, to change the background color of a field, you can set
Ackgound.color=rgb ("Right" (now (), ' HHMMSSF '), 1) *256/10,integer ("Right" (String (now (), ' HHMMSSF '), 1)) * 256/10,0)
Of course, you can not only change the background color, but also can change the font and so on any property, so that he can move up!

4 Make the selected row in the Data window look better
As you all know, when you select a row in the Data window, if you use PB-provided selection function SelectRow (), then the appearance is really not flattering, monotonous and traditional blue background, may be incompatible with your beautiful and vivid application. Is there any way to change it? Of course there is, please listen to my slow way.
Changing the background of a row is relatively simple, changing the Background property (BackgroundColor) of each column, can be changed automatically according to the mouse selection situation, and can return to the selected row may also require a certain skill. The following single-line selection and multiline selection resolution description.
Single line Selection
Single-line selection is simple, so we'll just change the expression of the background color of all fields to:
if (GetRow () =currentrow (), RGB (255,126,0), RGB (0,0,0))
Where the first color is the selected color, the second color is not selected. Then use GetRow () instead of the Getselectedrow () function to get the selected row.
Multi-line selection
Multi-line selection is more complex, if simply rely on changing the properties of the data window can not be achieved, we must use the Data window properties and code together to achieve
First, change the SQL statement in the Data window to add a calculated field: 0 as Flag,select statement to:
Select col1,col2, 1 as flag from TableName where ......,
When you return to the Data window painter, you will find one more field flag, which is where we use this field to save the information selected by the row.
Next, modify the background color properties for each field, set to: if (Flag=1,rgb (255,126,0), RGB (255,255,255))
Third: In the Data window control, increase the processing of the clicked event, the code is as follows:
If Row<1 then return//SetRedraw (FALSE)
If THIS.O B J e C t.flag[row]=1 then//If the row is selected, undo the selection, otherwise select the row
This. Object.flag[row]=0
Else
This. Object.flag[row]=1
End If
SetRedraw (True)

You can also customize the font, text properties, and so on for this selected line. The same principle, no longer repeat.

5 Initialize the Date field to the date of the day
Using the Column Specifications dialog box to set the initial value of the data is a better and more general method. To initialize a date field to the date of the day, set the initialization value to today instead of today (). Also set the initial value to NULL, you can use NULL instead of NULL ().

6 adjusting column order in DataWindow
In Gird-style datawindow, the order of the columns is arranged in the order that you choose column, and it cannot be changed. The order in which you want to change the columns must be recreated DataWindow.
Recently I found a way to change the order of the columns: Open the DataWindow you want to modify in the DataWindow artboard, then press the ' Preview ' button to switch to preview mode, select the column heading you want to move and drag to a predetermined position, then return to the DataWindow artboard, Save the disk.

7 Retrieve does not clear the original DataWindow data
When you call the Retrieve function, PowerBuilder automatically clears the original DataWindow and then retrieve the data. In the DataWindow Retrievestart event, return 2 is used so that the PowerBuilder does not clear the original data but appends new data.

8 beautify the DataWindow display effect
Make DataWindow's single-and-line display different colors, not only to make your application more professional, but also to make the data more readable. First bring up the DataWindow you need to change, in detail band press the right button to select Properties, select Expression_rs in the tab page, enter the following in the color attribute: (Note that the detail detail display segment right-click, Instead of on the column) IF (MOD (GETROW (), 2) =0,rgb (192, 192, 192), RGB (255, 255, 255)) Preview it now and see how it works.

9 Tips for building a nice grid datawindow with line
Although PowerBuilder has a grid-style datawindow, but not flexible enough, if you want to print a thick border or two lines, the inner box is a thin line of the table directly using the grid style DataWindow can not be achieved. So many people use tabular style datawindow, and then use line to implement grid. In the adjustment line position is a nerve-racking and hurt the eyes of the event, and once you need to adjust the row height, all work has to be re-try the following method, will greatly reduce your workload: in vertical lines, change its properties, on expression_rs tab, Y1 line on the input 0, Y2 line Input rowheight ()-1 in horizontal lines, set y1 and y2 = RowHeight ()-5 so PowerBuilder will automatically adjust the line coordinates, you only need to set the length of the horizontal lines and x1,x2 coordinates. Preview now and take a look at the effect! You no longer need to readjust the line position because of the height of the line.

10 How to create a report with the following form
Quantity Running Total
5,000 5,000
2,500 7,500
3,000 10,500
12,000 22,500
For the running Total column, we can use the computed column: Cumulativesum (Quantity for all) to achieve a gradual increment of the sum function.

11 The four steps identified before the data-feed buffer of the data window determine if the data type is correct. The Itemerror event is triggered if it is not correct. Determine whether the data conforms to the validation rules. If the validation rules are not met, the Itemerror event is also triggered. Determine if any data has been altered. Determines whether the data passes the ItemChanged event, and if the data and itemchanged repel, the Itemerror event is triggered.

12 How to find a column condition in DataWindow with a data type datetime
1. Use the following expression when the date condition to find is a constant:
Ls_find = "Datetime_col
= DateTime (' 1/1/1999 ') "
2. Use the following expression when the date condition that you want to find is a variable:
Ls_find = "Datetime_col = DateTime ('" + ls_date + "')"
3. Use the following expression when the date condition that you are looking for is a datetime data type:
Ls_find = "Datetime_col = DateTime ('" + String (ldt_datetime) + "')"

13 three ways to set the Data window Boolean property
PowerBuilder provides three ways to set the Boolean properties of the Data window, namely True/false, 1/0, ' Yes '/' No '. For example:
dw_1.Object.address.Visible = 0 Dw_1.Object.address.Visible = False dw_1.Object.address.Visible = ' No '
PowerBuilder saves the property as a string on processing, regardless of whether the property value is Boolean, long, or character.
For further understanding, you can export a data window and view its original code, and you can find that even the color property of a column is used with double-cited
Number of numbers to express.

14 How to quickly delete multiple lines in DataWindow
In the development process, you may often have multiple-row deletions, usually using circular statements:
For Ll_rowon = 1 to Dw_1.rowcount () Dw_1.deleterow (Ll_rowon) NEXT
A quick way to delete is to move the row to be deleted from the primary buffer to the delete buffer. For example, delete all the rows in the buffer:
Dw_1.rowsmove (dw_1, 1, Dw_1.rowcount, primary!, Dw_1, 1, delete!)
But don't forget to filter the rows in different buffers.

15 How to delete duplicate rows in DataWindow SQL syntax without using the SELECT distinct implementation
First sort the column you want to display unique values for: "City A" and then add the following filter string: "City < > City [-1] or GetRow () = 1"

16 How to display the line numbers of each group in a grouped form in DataWindow
When we display line numbers for each line of DataWindow, we can simply put an expression to GetRow () to calculate the column. For grouped DataWindow, however, to display the row numbers for each group separately, you should use the expression
GetRow ()-First (GetRow () for Group 1) + 1 computed column.

17 How to change the font color of the column to remind the user that this column has been modified
In the color property of the column, enter the following expression
IF (column_name < >column_name. Original, RGB (255, 0, 0), RGB (0, 0, 0)).
In this condition, if the column has changed, a red font is displayed, otherwise the black font is displayed. This expression is mainly used column_name < > column_name. Original compares the values of the top and the original columns to achieve the purpose of judgment.

18 move rows in the Data window, but not filter or delete operations
The Rowsdiscard () function does this by performing the removal work in the data window, but the moved row is not deleted or modified to save.

19 How to display the line numbers of the first and last rows of the current data in footer band in DataWindow in multiple lines of display
Let's look at the expression for two computed columns: IF (GetRow () = First (GetRow () for Page), 1, 0)//1 is the top row of the current page
IF (GetRow () < > 1 and GetRow () = Last (GetRow () for Page), 1, 0)//1 is the final row of the current page
As indicated above, the following computed column expression is set in Footer band:
' Rows ' + string (first (GetRow () for page) + "to" + string (Last (GetRow () for page) + ' is displayed '.
This function can be achieved.

20 Make editable Data window read-only
Sometimes you might want to use a data window for programming as a display purpose, and there are several ways to do this:
1. Create two data windows, one for editing and one for displaying
2. Set the taborder of all objects in the data window to 0.
3. You can also set the Protect property of a column in the Data window to on or off, but you cannot edit it using the Protect property
4. The Data window has a property (ReadOnly) that sets DataWindow to read-only, which is most convenient to use.

21 Data Window Check Duplicate rows
Dw_1.setsort ("user_id A")
Dw_1.sort ()
Dw_1.setfilter ("user_id = User_id[-1]")
Dw_1.filter ()
If Dw_1.rowcount () > 0 Then
Messagebox ("Note", "Duplicate user code.")
End If
Dw_1.setfilter ("")
Dw_1.filter ()

22 How to display the line numbers of each group in a grouped form in DataWindow
----When we display line numbers for each line of DataWindow, we can simply put an expression of getrow ()
----computed columns. For grouped DataWindow, however, to display the row numbers for each group separately, you should use the expression
GetRow ()-First (GetRow () for Group 1) + 1 computed column.

23 How to make certain columns of the data window fixed when other columns are pulled horizontally
////////////////////////////////////////////////////////////////
Function Description: Used to freeze the left scroll bar
change history: When a change or version is updated
//
////////////////////////////////////////////////////////////////
int I
if pane = 1 Then
i = integer (this.o b J e c T.datawindow.horizontalscrollposition2)
If I < 1 or isnull (i) then return
If Scrollpos > 0 Then
THIS.O B J e C t.datawindow.horizontalscrollposition = 0
End If
Else
i = integer (this. Object.DataWindow.HorizontalScrollSplit)
If I < 1 or isnull (i) then return
If i > Scrollpos then
THIS.O B J e C t.datawindow.horizontalscrollposition2 = i
End If
End If

24 in the Data window, if you want to make the properties of one column read-only, that is, the user is not allowed to modify, then simply set the table Order of this column to 0. However, in some cases
Some rows of this column need to be modified, and some rows cannot be modified, which will use the Protect property of this column. Open the Expression_rs in the properties of the column, and enter the conditional discriminant in the Protect
Expression For example: Allow the user to modify the newly added record, while the retrieved record does not allow the modification. Conditional discriminant can be written as follows:
if (isrownew (), 0, 1)
You can dynamically modify the Protect property in PowerScript:
Dw_1.modify ("Column_name_here. Protect= ' 1~tif (isrownew (), 0, 1) ' ")
This way, only newly appended records in the DataWindow can be modified, while other records are read-only.

25 control the number of rows displayed per page in the DataWindow
1, add a calculation field in the DataWindow, named: ceil_page, this calculation field must be placed in the detail segment,
Expression_r Input Ceiling (GetRow ()/25) 25 means that 25 rows per page can be printed or a parameter.
2, group, select Menu Rowscreate Group, select Ceil_page
GROUP BY Ceil_page and select New page on Group break (meaning that the new group starts with a page change).
3. Set this calculated field to hidden (in the Expression_r page of the property page, write 0 in the Visible property).
4. Fill Empty line:
Write the following code in the window's Open event:
Long li_count,li_i
Li_count=dw_1.retrieve ()
If mod (li_count,25) <>0 Then
For Li_i=1 to 25-mod (li_count,25)
Dw_1.insertrow (0)
Next
End If

26 Data Window Closequery event: Prompt to save data
Dw_1.accepttext ()
IF Dw_1.modifiedcount () + dw_1.deletedcount () > 0 Then
CHOOSE Case MessageBox ("Action Tip", "Data has changed, is it saved?", question!,yesnocancel!,1)
Case 1
Cb_save. Triggerevent (clicked!)
Case 2
Return 0//Close the window without any action
Case 3
Return 1//does not run the Close event to maintain the original condition
END CHOOSE
END IF

The Getchild function is primarily used to obtain a data window's sub-data window
The function can be used in two cases, 1, take out the data window object of the drop-down data window;
2. Remove the Child Data window object embedded in the composite style (composite) Data Window object.
Syntax: integer dwcontrol. Getchild (string name, REF datawindowchild
dwchildvariable)

Example 1 This procedure takes out a composite data window object with two sub-data windows and filters them, and sorts the operations.

String Ls_filter
Datawindowchild dwc_czrw,dwc_czx//defining child data window variables
Dw_dy. Settranso B J e c T (SQLCA)
Dw_dy. Retrieve ()
Dw_dy. Getchild ("Dw_2", DWC_CZRW)
Dw_dy. Getchild ("Dw_1", DWC_CZX)
Ls_filter = "CZRW_BH = '" +dw_3.getitemstring (Dw_3.getrow (), "CZRW_BH") + "'"//filter conditions
DWC_CZRW. SetFilter (Ls_filter)
DWC_CZRW. Filter ()
Ls_filter = "CZX_RWBH = '" +dw_3.getitemstring (Dw_3.getrow (), "CZRW_BH") + "'"
Dwc_czx. Setsort ("Czx_sx A")
Dwc_czx. Sort ()
Dwc_czx. SetFilter (Ls_filter)
Dwc_czx.filter ()
It is also possible to manipulate data in the Child Data window by means of data sharing (Sharedata).
Accesses the composite Data Window object. Method: dw_dy.o B J E c T.DW_1.O b J e c T. Object
Example 2 drop-down data window dynamic filtering
The following script is written in the Itemfocuschanged event of the data window Dw_1:
Integer Rtncode
String Ls_nowfld,ls_deptid,ls_sql
Datawindowchild Fld_child
Rtncode = Dw_1.getchild ("unit_id", fld_child)//Get a handle to the UNIT_ID field name pull Data window
If Rtncode =-1 Then MessageBox ("Error!", "Not dropdown data Window!")
Fld_child. Settransobject (SQLCA)//Set Transaction object
Ls_sql = Lower (fld_child. Getsqlselect ())//Get DDDW SQL statement
Remove the WHERE conditional clause in the SQL statement, such as a WHERE condition clause in the original SQL statement, where you need to perform a more
Complex processing should be subject to specific circumstances.
If Pos (Ls_sql, "where") >0 then Ls_sql = Left (Ls_sql,pos (Ls_sql, "where"))
To reset a WHERE Condition clause in an SQL statement
Ls_deptid=dw_1.object.dept_id[getrow ()]//Get current dept_id selected value
Ls_sql = Ls_sql + "Where dept_id = '" +trim (ls_deptid) + "'"
To reset the SQL statement
Fld_child. Setsqlselect (Ls_sql)
Fld_child. Retrieve ()//Get the data that satisfies the condition

28 getting data from the data window
Single: Suppose we want to read the first data of the dept_id field, which can be represented in the following way: li_id = dw_1.o B J e C T.dept_id[1]
Suppose we want to read the data from the second field in the first row, which can be represented in the following way: Ls_name = dw_1.o B J e C t.data[1,2]
Suppose we want to read all the data of the dept_id field, which can be represented in the following way: Li_array = dw_1.o B J e C t.dept_id. Current
Suppose we want to read the first data of the dept_id field in the filter buffer, which can be represented in the following way: li_id = dw_1.o B J e C t.dept_id. Filter
[1]
Suppose we want to read data from the first field of the second data to the two fields of the third data, indicating: Lstr_array = dw_1.o B J e C t.data[2,1,3,2]
Suppose we want to read the entire second data, which can be represented in the following way: Lstr_dept = dw_1.o B J e C T.data[2]
Use GETITEMX () function X for string number, etc.
Lstr_name = dw_1.getitemstring (Li_count, "Emp_name") Li_count for which article
Multiple: string ls_name[]
Ls_name = dw_ 1.o b J e C t.emp_name.current
General format for reading data: Data window controls. Retrieve () returns number, 1 is error
Adds a Data Data window control. InsertRow (number of rows) parameter is 0 plus to the last
The data for the Delete Data window control. DeleteRow (number of rows)
Data filter L Data window control. SetFilter (conditional string).
The Data window control. Filter () Usage: Move data that does not conform to the filter in the primary buffer (Primary) to the filter buffer
Within
Example: string Ls_exp ls_exp = "dept_id =" Dw_1.setfilter (ls_exp) Dw_1.filter ()
Sort Dw_1.setsort ("dept_id") Dw_1.sort ()
Clears the data from all buffers (buffer) Dw_1.reset ()
Calculates the number of data. For example: Dw_1.rowcount () similar to:. Deletedcount (). Modifiedcount (). Filteredcount ()
The data window's scrolling data window control. Scrolltorow (number of rows)

29 Data Window Properties changed:
Describes the color of the data window object itself, which can be expressed as follows: Long ll_color Ll_color = dw_emplist. Describe ("Datawindow.color")
Describes the color of the caption dept_id_t within the Data Window object, which can be expressed as follows: Long ll_color Ll_color = dw_emplist. Describe ("Dept_id_t.color")
Modify the Data Window object itself color, can be expressed as follows: Dw_emplist. Modify ("Datawindow.color = 255")
Modifies the color of the caption dept_id within the Data Window object, which can be expressed as follows: Dw_emplist. Modify ("Dept_id_t.color = 255")
Let's say we want to give the downside when the program runs: When the salary is more than 50000, the red is displayed, and the black is shown below 50000. The program is written as follows:
ls_modstring = "Salary.color = ' 0~tif (Salary > 50000,255,0) '"
Dw_1.modify (ls_modstring)

30 gets the band of the object to which the current mouse is pointing
String Str_band
Str_band=getbandatpointer ()//Gets the band of the object to which the current mouse is pointing
Str_band=left (Str_band, (POS (Str_band, ' ~t ')-1)//Get "header", "detail", etc.
If str_band<> ' header ' then return//Click Non-header, exit
31 get the name of the Column object to which the mouse is pointing
Str_o B J e C T=getobjectatpointer ()//Get the name of the object currently pointed to by the mouse
Str_o B J e c T=left (Str_o B J e c T, (POS (str_o b J e c T, ' ~t ')-1))
Get Column Object name (default to Column name _t column header)
Str_column=left (Str_o b J e c T, (Len (Str_title)-2))
Determine if the name is a column name
If This.describe (str_column+ ". Band") = '! ' then return//is not a column name, that is, the column headings are not named according to normal rules.

32 Get current row, column, head, column//this for Data window
Li_col = this. GetColumn ()
Li_colcount = Long (describe (this, "Datawindow.column.count"))
Ll_row = this. GetRow ()
Ll_rowcount = this. RowCount ()
Set the current row, column
Scrolltorow (This,ll_row)
Setrow (This,ll_row)
Setcolumn (This,li_col)
This. SetFocus ()

33 Get all column headings
Ll_colnum = Long (dw_1.o b J e c t.datawindow.column.count)
For i = 1 to ll_colnum
//Get header name
Ls_ ColName = Dw_1.describe (' # ' + string (i) + ". Name") + "_t"
Ls_value = dw_1.describe (Ls_colname + ". Text")
Next

34 How do I get the data window with code to summarize the values of the computed columns?
String ls_value
Ls_value = Dw_1.describe ("Uate (" ' Compute_1 ', 1) ")
If it is a numeric type, you want to convert.

35 Gets the column header, column name, database field name that you clicked
String Ls_dwo
Long ll_pos
String Ls_type
String Ls_title
String Ls_ Column
String Ls_dbname
If not KeyDown (keycontrol!) and then return
Ls_dwo = Dwo. Name
If trim (ls_dwo) = ' or IsNull (LS_DWO) then return
Ls_type = this.describe (Ls_dwo + '. Type ')
if ls_type = ' C Olumn ' then
Ls_title = this.describe (Ls_dwo + ' _t.text ')//title
Ls_column = this.describe (Ls_dwo + '). Name ')//Data window column name
Ls_dbname = this.describe (Ls_dwo + '. dbname ')//database field name
MessageBox (' info ',  ' title text  : ' + ls _title + &
' ~r~n Data Window column name: ' + ls_column + &
' ~r~n database field name: ' + ls_dbname '
End If

36 window for W_GCDE inside, put in a dw_1, how to get the contents of a column Value yuonghu_id column within the Dw_1
Method:
Long Lng_column_count
Integer i
String str_column[]//Column name
String str_column_text[]//text's name
Get the total number of columns in the Data window
Lng_column_count = Long (Dw_1.describe ("DataWindow.Column.Count"))
Loops Read sequentially
For i = 1 to Lng_column_count
Str_column[i] = Dw_1.describe ("#" +string (i) + ". Name")
Str_column_text[i] = Dw_1.describe (Str_column[i] + "_t.text")
Next

37 implement current certain with mouse move in DDDW
Datawindowchild Ldwc_child
String Ls_pointer
Long Ll_row

Getchild ("dept_id", Ldwc_child)//Replace The column name "dept_id" as you needed

IF hwndchild = Handle (ldwc_child) Then
If Notificationcode = 2311 then//dddw MouseMove event
Get the mouse in the row
Ls_pointer = Ldwc_child.getobjectatpointer ()
Ll_row=long (Mid (Ls_pointer, Pos (Ls_pointer, "~t") + 1))
Move to the mouse row
IF Ldwc_child.getrow () <> ll_row and ll_row > 0 Then
Ldwc_child.scrolltorow (Ll_row)
END IF
End If
END IF

38 implementation does not change pages after printing a DataWindow
First print the DataWindow print to a printed file, and the other print into the PRN, and then the printed file will be printed on the line.
Such as:
Datawindow_control1.object.datawindow.print.filename= "C:PRINTFILEPATHEXAM_1.PRN"
Datawindow_control2.object.datawindow.print.filename= "C:PRINTFILEPATHEXAM_1.PRN"
Dw_1.print ()
Dw_2.print ()
Run ("Print//d:\printservenamesharename" C:PRINTFILEPATHEXAM_1.PRN ")
D:\printservenamesharename Printer Name

PB Data Window Setup operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.