Using a Combo Box to Dynamically Redefine a Browse
The OnChange event of the SearchBy combo box runs the following Xbasic code, which:
sets the title of the Browse1 list
retrieves a new sorted list of non-null values for Browse1
resets the MULSTBTN1 multi-state (A to Z) button at the bottom of the screen
Xbasic Code Run by the OnChange Event of the SearchBy Combo Box
dim tbl as P topparent:Browse1:Lastname.Object.Column_title = searchby.text tbl = table.current() tbl.order(\ searchby.text,\ searchby.text + " <> ''"\ ) mulstbtn1.text = "1" browse1.refresh()
An Explanation of the Code
The first line creates a pointer variable named tbl to refer to table (and the data) that the Customer Information form displays.
dim tbl as P
The following line sets the column heading of the Browse1 list to be the same as the entry selected in the SearchBy combo box. Note that the name of the column is "Lastname", which is how it was initialized. This name remains the same, even though the browse may be displaying another field from the table.
topparent:Browse1:Lastname.Object.Column_title = searchby.text
Each form is based upon a table (or set). The Customer Information form is based on the Customer table. This line points tbl at the Customer table.
tbl = table.current()
The next line sorts the table using the field that was selected by the SearchBy combo box. searchby.text is the field that will be retrieved. searchby.text + " <> ''" is a character expression restricts (filters) the records that will be returned. It evaluates to: searchby.text <> ''.
tbl.order(searchby.text, searchby.text + " <> ''")
The MULSTBTN1 multi-state button allows the user to further filter the contents of Browse1 to be only those records beginning with the selected record. This line deselects the current selection, if any, so that all records selected by the above filter expression will appear. It does this by choosing "1", which is not a valid member of the A to Z set.
mulstbtn1.text = "1"
Finally, we force Browse1 to display its new contents.