powerbuilderdatawindow

Dropdown datawindow display column behavior versus filter


I have a datawindow containing x number of rows. The first column -- which I'll call "employee" -- is a dropdown datawindow with a data column pointing to an employee ID field, and a display column pointing to an employee name field. When adding a row, this column is filled based on the user's dropdown selection. Additionally, a filter is applied to the employee column's DatawindowChild, so that the user may not select an employee who does not match the current filter.

The problem:

When the filter expression changes such that it no longer matches existing rows, the employee column can no longer reference a display value for the current employee ID, because the corresponding row is in the dropdown datawindow's filter buffer. The result is that the data value is displayed instead.

What would be a smart workaround?

Also, one additional thing to consider is that I can't apply a matching filter to the main datawindow, because one of the requirements is that all rows remain visible at all times.

Thanks in advance.

Edit: Powerbuilder 2017 R2.


Solution

  • So after trying every trick I could think of using filters and coming up short, I ended up settling on a messy solution that partially subverts datawindow behavior, but works.

    I reasoned that the only way to fix display issues caused by a mismatch between selectable values in a dropdown datawindow and actual values entered into the column was to make sure that a mismatch can never actually occur.

    I made a new employee dropdown datawindow column with both display and data columns pointing to the employee name field. The user selects an employee name, and the employee ID is then manually fetched from the datawindow child using Find and GetItemString where necessary. The result is that the dropdown datawindow is no longer able to manipulate data -- this now has to be done manually in code, -- but there are no visual changes to existing rows when modifying filter expressions.

    Before:

    ls_employee = dw_1.GetItemString(row, "employee") //Returns employee ID
    

    After:

    ls_employee = dw_1.GetItemString(row, "employee") //Returns employee name
    ls_employee = ldwc_employee.GetItemString(ldwc_employee.Find("employee_name = '" + ls_employee + "'", 1, ldwc_employee.RowCount()), "employee_id") //Find row number and fetch ID
    

    Then, because the user isn't actually inserting PK/FK values into the table anymore, the employee ID has to be manually set on the old (hidden) employee ID column before calling update.

    dw_1.SetItem(row, "employee_id", ls_employee)
    

    I'm not completely happy with this solution since it makes using a dropdown datawindow ultimately pointless. It also fails to account for cases where the find can return the wrong row number if two employees happen to have the same first and last names, but that's acceptable in my case because those situations are extremely unlikely to ever occur.

    So I'm not proud of it, but there it is anyway.