About   -   Contact   -   Purchase   -   Search   -   What's New

How to filter Dropdown Datawindows
This tip was submitted by Chris Allison.

There's a steady flow of posts asking "how do I filter dropdown datawindows?" Here's one answer that doesn't rely on zero height columns.

Imagine an ordering system in which orders can be "new", "pending", "confirmed" or "cancelled". New orders can only be changed to cancelled or pending. Pending orders can only be changed to cancelled or confirmed. Cancelled and confirmed orders can not be changed.

Now imagine a datawindow that displays all orders. There are columns for order number and order status. The order status can be updated and is implemented as a dropdown datawindow where the display column (cancelled, confirmed, new, pending) is mapped to the data column (1, 2, 3, 4).

How does one correctly display the order status whilst at the same time filtering the dropdown datawindow?

The initial solution, trapping the pbm_dropdown event and using the GetChild, SetFilter and Filter methods doesn't quite work. Imagine two orders, one new and one confirmed. Filtering the dropdown datawindow for the new order so as to display cancelled, new and pending (data values 1, 3 and 4) is okay for the new order but as soon as confirmed is filtered out of the dropdown datawindow the confirmed order status is incorrectly displayed as 2.

We need to find some way of preventing the repaint while the dropdown datawindow is dropped.

The following is a minimal implementation. It is recommended that it be packaged as a datawindow service; for more detail please contact the author. In particular, it is recommended that the of_Filter method be used in conjunction with an of_Register method whereby datawindows, columns and filter strings be mapped together so that of_Filter methods needn't be written for each and every dropdown datawindow.

Step 1 - declare instance variables

boolean ib_dropdowndropped = False
boolean ib_dropdownredrawn = True

Step 2 - extend the pbm_dropdown event

ib_dropdowndropped = True
ib_dropdownredrawn = False
ib_dropdownredrawn = True

Step 3 - extend the pbm_ncpaint event

If (ib_dropdowndropped And ib_dropdownredrawn) Then
 ib_dropdowndropped = False
 ib_dropdownredrawn = False
 ib_dropdownredrawn = True
End If

Step 4 - write the of_Filter (boolean ab_switch) subroutine

datawindowchild ldwc
long ll_getitemnumber
string ls_setfilter = ""

If (ab_switch) Then
 ll_getitemnumber = GetItemNumber(GetRow(), "order_status_id")
 If (ll_getitemnumber = 1) Then // cancelled -> cancelled
  ls_setfilter = "(order_status_id = 1)"
 ElseIf (ll_getitemnumber = 2) Then // confirmed -> confirmed
  ls_setfilter = "(order_status_id = 2)"
 ElseIf (ll_getitemnumber = 3) Then // new -> cancelled, new, pending
  ls_setfilter = "(order_status_id = 1) or (order_status_id = 3) or
(order_status_id = 4)"
 ElseIf (ll_getitemnumber = 4) Then // pending -> cancelled, confirmed,
  ls_setfilter = "(order_status_id = 1) or (order_status_id = 2) or
(order_status_id = 4)"
 End If
End If

GetChild("order_status_id", ldwc)

Top of Page

Legal Notice

Ken Howe 2011