Is there a way to handle the dynamic change of a dropdown for a single row in a grid-based datawindow?
Example:
NAME LIKABILITY PURCHASED IN COLOUR
(Text) (DropDown*) (Text) (Text)
Bananas [Good] Hands Yellow
[Bad]
[Bananas are good]
Apples [Good] Bags Red
[Bad]
Given the above is a grid-based datawindow, where the fields NAME
,PURCHASED IN
and COLOUR
are text fields, where as the LIKABILITY
field is a dropdown*.
I say dropdown* because the same visual representation can be created by using a DropDownList (hardcoded within the datawindow element at design time), or a DropDownDW (or DDDW, a select statement that can be based on other elements in the datawindow).
However, there is no way I can get Bananas
having it's 3 dropdowns, while Apples has only 2.
If I enter multiple rows of Bananas
, then all rows have 3 dropdowns, but as soon as I add an Apples row, all dropdowns revert to 2 selections.
To attempt to achieve this functionality, I have tried the following options:
dw_1.Object.likability.values("Good~tG/Bad~tB/Bananas are good~tDRWHO")
on ue_itemchange when editing NAME.
FAILS: edits all instances of LIKABILITY instead of the current row.
Duplicate Dropdowns, having one filtered, one unfiltered selection list per row, visible based on NAME selection.
FAILS: can't set visibility/overlapping columns on grid-based datawindow. (Source)
Hard-code display value as Database value, or Vice Versa. Have GOOD
,BAD
,BANANASAREGOOD
as the display and database values, and change handling of options from G, B, DRWHO to these new values.
FAILS: 3rd option appears for all rows, still selectable on Apple rows, which is wrong.
DDDW retrieve list of options for dropdown. Create a DDDW that uses the value of NAME to determine what selections it should have for the dropdown.
FAILS: edits all instances of the dropdown, not just the current row.
DDDW retrieve counter of options available (if B then 3 else 2), then have duplicate dropdown columns that protect/unprotect based on DDDW counter.
FAILS: Can't autoselect dddw value to populate column to cause protect on other two columns, ugly solution in any case.
There is now a bounty on this question for anyone who can give me a solution that will enable me to edit a dropdown column for a single row on a grid-based datawindow in PB 10.5
So, the answer to your question is no, you can't have unique contents in DropDownListBoxes (or DropDownDataWindows for that matter) on a row-by-row basis.
The solution to your problem is more complex. You can change the contents of the drop down on RowFocusChanged, but what happens to the presentation on rows where the code value is no longer in the list of values? Only the code value is displayed. It's not great when you're not on a particular row if R is shown instead of Red. So, a common solution is to have two controls, directly on top of one another, to represent that data: one that is visible when the row has focus (the drop down whatever) and the one that is visible when some other row has focus, that shows the display value of the code. In the past I've done this with static text or a dummy edit-style column as the second control, and set the value on the ItemChanged of the first column. However, this morning I'm speculating that you could do this without scripting if the second control was a drop-down column, pointing to the same column in the data set, that always contained the full set of values. I'll leave the experiment (and the few other pieces needed to make this work, like what happens when the user clicks on the second control from another row) up to you.
Good luck,
Terry.
Addendum
You asked about how things are done row by row. This is going to be like Christmas for you (or some other culturally appropriate massive gift-receiving holiday). See in the Properties pane in the DataWindow painter all the elements that have a button to the right with an equals sign? That lets you enter an expression that will evaluate on a row-by-row basis to determine the value of the attribute. To enter an expression so that a field is only visible when it is the current row?
if (getrow() = currentrow(), 1, 0)
You can also Modify() these expressions at run time. I'll leave you to the help to dig that up. The help also gives you a list of attributes for each DataWindow control element, which includes in the table whether or not each attribute takes an expression. (The equals buttons are not 100% of the story; not all expressionable attributes can be expressioned through the IDE.)
Side note: If you get expressions and learn how to master them, you'll get the power of the DataWindow.
As for grids, my second suggestion of column over column won't work in grids, obviously enough. That's the time to fall back to using a column and a static text, for instance, with an ItemChanged script.
T.