Possible to hide/show field based on condition?

Is there a way to hide/show a text field or check box based on a condition (Something I did a lot in Filemaker).
For example I want to see specific checkboxes when choosing a specific row from a popup menu.

I tried things like Show or give a checkbox a True state when clicking a button, but this doesn’t seem the way to go.

Please always show your code. Of course, showing/hiding controls should work.

Are you using .visible?

Yes, I tried that but I get the error message that this isn’t a function.

I placed this code in an Action in the Show Button:

chkOrdinaryWorldActivity.Visible = True

aaah… thanks! So simple when you see the solution :slight_smile:

1 Like

It works great, but some times, fields are not showing up even when the code is correct. It seems that this happens when fields are on top of each other and prevent a lower field from being showed even when the upper field is set to .Visible = false. It’s important for me that I can stack fields on top of each other and only show the ones I need. Is there a logic here I should be aware of?

You might make the upper field transparent - I’ve not tried this so don’t know whether it has the desired effect. Or lay the controls out non-overlapping, but then as you hide one, move another to the location of the one you just hid.

Is there a logic here I should be aware of?
No, and yes.

Stacked controls can cause cascading paint events if they are both visible.
Also makes it hard to arrange your windows at design time.
Sometimes it makes more sense to group controls inside containercontrols , and show/hide the containers.

As long as you make items visible when they should be, and invisible when they should be, it should all work.

Typically code for that would look like:

dim nMode as boolean

if (wewanttoamendnames) then 
nMode = true
nMode = true
end if

namefield1.visible = nMode
namefield2.visible = nMode
namefield3.visible = nMode

Telephonefield1.visible = not nMode
Telephonefield2.visible = not nMode
Telephonefield3.visible = not nMode

The fields are showing based on a row chosen in a popup menu, I use this code for this:

if PopupMenuTypes.SelectedRowIndex > 9 then
chkBeliefInnerNeedsStep1.Visible = true
Elseif PopupMenuTypes.SelectedRowIndex < 10 then
chkBeliefInnerNeedsStep1.Visible = false
end if

all you need

Yes, the showing/hiding works great, but only when I position the fields not on top of each other and that is what I need.

Have you tried applying the same logic to ‘the other control’ at the same time?
(Have you tried my code instead of yours? Its not the same)

Without your code, we cant see what you can see.

chkBeliefInnerNeedsStep1.Visible = PopupMenuTypes.SelectedRowIndex > 9
theothercontrolinthesameplace.visible = not( PopupMenuTypes.SelectedRowIndex > 9)

While testing, move one of the controls so that it is not covered.
Then watch to see if the right controls become visible or invisible

Don’t do that. Place your controls on different pages of a page view and switch between the pages. Controls on top of each other will not be very manageable if you have lots of controls.


Actually this is better if you are doing something like Preferences. Preferences tend to cluster into groups for the same purpose, so you put each set of controls on its own page. I use a PagePanel for this.

You can also try moving controls outside of the confines of the window or container control when hiding them so they are not actually on top of each other. Use left -100 when hidden and the left position the control currently has when visible.

1 Like

Is there a chance that by dragging a control over the top of another, you have made the second one a ‘child’ of the first?

(The parent will show red in the IDE)

If that is the case, both will vanish when the parent is made invisible.
Drag the top one well away from the other control, and it will become a child of the window.
Then select it and use the arrows on the keyboard to slide it into place.

Or set chkBeliefInnerNeedsStep1.parent = self // or nil
in the open event of the window

1 Like

Thanks for the advice, I used the PagePanel, placed the checkboxes on different panels and got it to work:

if PopupMenuTypes.SelectedRowIndex > 9 then
PPActionStep10.SelectedPanelIndex = 1

Elseif PopupMenuTypes.SelectedRowIndex < 10 then
PPActionStep10.SelectedPanelIndex = 0

end if

1 Like

Hurrah :slight_smile:

So just out of curiosity why did you not consider using a single checkbox and change it’s properties and action depending on the popup menu selection?

That is what I was trying, I am using lots of checkboxes as shown in the screenshot. In this screenshot btw, the checkboxes are hiding and showing correctly based on the row choose in the drop menu. Not sure why it doesn’t work on another place.

Screenshot 2022-07-31 at 15.21.32