Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown Missing Data

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,826
JP
Hi All,
I've been trying to figure out an issue I have with a dropdown combobox I've had for a couple of days now.
There are 2 such boxes on the same form, and one was essentially copied from the other. The only significant difference between the two is their Requery() function, but I don't really see how that can be the issue.

What's happening is, I have the two boxes set to different control sources. Their dropdown values come from a code table, and populated into This.SourceArray in the Requery().

Everything seems fine, I select the values from each of the two dropdowns, (one is driven by the other) so when the contents of the available dropdown on the left changes, then the contents of the dropdown on the right (what you can select) are updated.

So If I pick for instance, T&E from the one on the left, the options in the second become Breakfast, Lunch, Dinner. If I change the left dropdown to Corporate then the options in the right box change to Utility, License, Supplies.

I pick the items I need, and that's all fine. BUT when I exit the form and come back in, the value in the box on the left is there, but on the right it's not. If I "edit" the field, as soon as I click the dropdown, it's on the correct item (what is stored in the table, and reflects the control source value), but it doesn't appear unless I click on the dropdown, then I can see it. When I check the data table (actually there is a grid on the form with the values too), they are correct, it's just not appearing in my dropdown.
Any idea what could cause this?


Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
The control source are fields in the Expense Detail table.
So one is ExpenseType and the other is ExpensePurpose.

The Requrry of ExpenseType is:
Code:
DIMENSION This.SourceArray(1,1)
This.SourceArray(1) = '-None-'
*
SELECT DISTINCT EXPENSETYPE FROM CTEXPENSETYPE INTO ARRAY This.SourceArray

And the Requery of the ExpensePurpose is:
Code:
DIMENSION This.SourceArray(1,1)
This.SourceArray(1) = '-None-'
*
SELECT DISTINCT EXPENSEPURPOSE FROM CTEXPENSETYPE INTO ARRAY This.SourceArray;
	WHERE ALLTRIM(This.Parent.cboExpenseType.Value) = ALLTRIM(CTEXPENSETYPE.EXPENSETYPE)

I'm still perplexed by it. I can't find anything running under debug mode that give any indication why the field is correct, but the dropdown isn't.
When I first select it, it shows in the field, but if I leave and come back, it's gone. If I click down as if to select it, it is always on the right value in the list, and the value is in the table.
Stumped...

Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
You might have something in form.activate or form.refresh or foprm.draw causing that. And if the active rows changed you also don't change the second ComboBox, you only do so triggered by the first CombobBox, right?

Ensure some things:
1. When you only want items picked from rowsource items, don't use the default mixed mode style of the ComboBox also acting as a TextBox and set Style=2 to get a DropDown list.
2. Have the first column with what you want to display, as the collapsed ComboBox always displays that and use a second column of the RowSource to have an ID to be able to use a foreign key as the ControlSource two ways and for that to work set BoundColumn=2. No need for BoundTo =.T., that is about the behavior of Value in regards to what this sets and what ListIndex will cause. See the BoundTo help topic.

No matter what RowSourceType you provide, in the end, the ComboBox always copies that to the native List or ListItem array, even when using the rowsource type array. And that's the native Requery code, if you write your own this base code still runs, to suppress it NODEFAULT would be necessary, but it might run before you recreate the SourceArray. You can call the base code via [tt]ComboBox::Requery()[/tt] (no typo here, I mean double colon). It can't hurt to put this as last line of your Requery code to ensure it repopulates List/ListItem from the now curret SourceArray.

As initially said there's got to be some reason rather in form.deactivate or .activate or .refresh etc. Notice form.activate runs with each activate, not only the first, in many scenarios, it would be helpful if it only ran once and you often find frameworks setting a flag to only execute when that flag is not yet set. People used to this mechanism fall for getting used to this being a late init, but it's still a repeatedly happening event. IIRC you had an issue because of that some time past.

The picked item and DisplayValue to disappear could easily happen when you share a DataSession and other forms fiddle with active records by intent or not, influencing the CombooBoxes via ControlSource. A way to ensure no whacky situation would be to requery the purpose ComboBox at every form.activate and of course then refresh it to get it's DisplayValue according to the current ControlSource value.

Also if you click another row in the grid, this could cause trouble, as the possible items in the purpose ComboBox don't update to the correct items for the expense type that time since you only trigger that update from the change of the first ComboBox and not from changing grid row. Then even a valid expense purpose doesn't set the purpose combo to the correct item as it might not be part of the last requery result of a previous expense type.

Note: Requery() does refresh the List/ListItem from the rowsource, it does only indirectly influence the display, as of course a missing item can't be displayed anymore. After that is current a Refresh() causes the selected item and DisplayValue to be according to the ControlsSource, it often helps to do both, even if the RowSource is unchanged and a Requery() seems unnecessary, but to trigger the ControlSource to determine the DisplayValue you Refresh(). And remember a Style=0 real combo with TextBox feature will be unimpressed by that as it's always valid to have any text in DisplayValue. The Controlsource then isn't two-way, at least not always. What's sure is picking an item then sets ControlSource and DisplayValue correctly, but since any DisplayValue is possible it doesn't get triggered by ControlSource changes. even when acting on it via Requery() and Refresh(). That makes Controlsource bound one-way.

I know you said "nothing changed", but in that case "nothing happens"... I think I pointed out coverage logging as a means to see what code runs, more reliable than debugging, as having the debugger windows open and clicking there also causes all kinds of deactivate/activate events not happening without debugging, so the debugger is not well suited for debugging event problems.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I have seen drop down boxes exhibit odd behaviour before. That's why some people advocate using grids to provide similar functionality.

I have one form where the contents of a drop down box are likely to change, for that I prefer to use a cursor rather than an array...

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
after you run the query to select into the array....

mycbo.rowsource = mycbo.rowsource

to cause the combo to take another look at the source.

hth

n
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top