Specifies sort criteria for a DataWindow control or DataStore.
integer dwcontrol.SetSort ( string format )
Argument |
Description |
---|---|
dwcontrol |
A reference to a DataWindow control, DataStore, or child DataWindow. |
format |
A string whose value is valid sort criteria for the DataWindow (see Usage). The expression includes column names or numbers. A column number must be preceded by a pound sign (#). If format is NULL, PocketBuilder prompts you to enter the sort criteria. |
Returns 1 if it succeeds and -1 if an error occurs.
A DataWindow object can have sort criteria specified as part of its definition. SetSort overrides the definition, providing new sort criteria for the DataWindow. However, it does not actually sort the rows. Call the Sort method to perform the actual sorting.
The sort criteria for a column has one of the forms shown in the following table, depending on whether you specify the column by name or number. Order is either A for ascending or D for descending order. You can specify secondary sorting by specifying criteria for additional columns in the format string. Separate each column specification with a comma.
Syntax for sort order |
Examples |
---|---|
columnname order |
"emp_lname A" "emp_lname A, dept_id D" |
# columnnumber order |
"#3 A" |
To let the user specify the sort criteria for a DataWindow control, you can pass a null string to the SetSort method. PocketBuilder displays the Specify Sort Columns dialog with the sort specifications blank. Then you can call Sort to apply the user’s criteria. You cannot pass a null string to the SetSort method for a DataStore object.
This statement sets the sort criteria for dw_employee so emp_status is sorted in ascending order and within each employee status, emp_salary is sorted in descending order:
dw_employee.SetSort("emp_status A, emp_salary D")
If emp_status is column 1 and emp_salary is column 5 in dw_employee, then the following statement is equivalent to the sort specification above:
dw_employee.SetSort("#1 A, #5 D")
This example defines sort criteria to sort the status column in ascending order and the salary column in descending order within status. After assigning the sort criteria to the DataWindow control dw_emp, it sorts dw_emp:
string newsort
newsort = "emp_status A, emp_salary D"
dw_emp.SetSort(newsort)
dw_emp.Sort( )
The following example sets the sort criteria for dw_main to null, causing PocketBuilder to display the Specify Sort Columns dialog so that the user can specify sort criteria. The Sort method applies the criteria the user specifies:
string null_str
SetNull(null_str)
dw_main.SetSort(null_str)
dw_main.Sort( )
Copyright © 2004. Sybase Inc. All rights reserved. |
![]() |