Is it possible to auto-arrange controls on a web application?

[code]I’m building a web application that is fairly simple in that each individual control is positioned line by line on the page. For example, the page looks something like this:

  1. drop-down

  2. drop-down

  3. check box

  4. dropdown

  5. textbox

  6. checkbox

  7. drop-down

  8. drop-down

  9. drop-down

  10. button

This is just an example. Mine has over 40 controls on it. Now, based on the selection in drop-down box 1 I need to hide certain fields, say 2, 5, 6 and 9. What I want is for the other controls to automatically scoot up to keep a consistent layout so it would look something like this:

  1. drop-down

  2. check box

  3. dropdown

  4. drop-down

  5. drop-down

  6. button

Rather than like this:

  1. drop-down

  2. check box

  3. dropdown

  4. drop-down

  5. drop-down

  6. button

Does the web app framework support anything like this? There six different selections in drop-down 1 and each has its own fields that need to be hidden so trying to manually reposition 40+ fields whenever a different selection is made will be a nightmare. I’m using Xojo 2015r1.
[/code]

Yes and no: you manage controls that become visible (or invisible) with their visible property. You can set such properties in the selection changed event of the drop-down (a webpopupmenu). you can also manage the content of subsequent drop-down menus based on the selection in the first one using the same event. This is something that I do in some apps, when I want to restrict subsequent choices based on choices already made. in short, you have the events and properties available to do what you want to accomplish, but the code is yours to write.

Now, if your requirement is goes beyond hiding or showing fields and you also want to reposition them, then the logic can become quite difficult to manage. Theoretically, you could use the selection changed event of the first or of any subsequent dropdown and manage the position of the controls.

Your design seems quite complex. Have you considered using webcontainers to group together a number of controls, or even webdialogs that you can manage from the main page? Perhaps a step back and a slight change of design can simplify the management of all the controls.

To a certain extent, perhaps Rubberviews WE can help you. You could contact @Michel Bujardet for a better sense of what it can do for you.

Thank you for your reply.

I was afraid of that. Automatically repositioning the controls is what I needed. I’ve already configured the hiding based on the selected item, I just wanted to avoid having a bunch of gaps where the hidden controls are. Rubberview WE looks like a neat product but from what I’ve seen it only resizes and moves the controls based on the screen size and doesn’t actually reposition the controls based on space availability. I was looking for functionality similar to what you would find in the .NET FlowLayoutPanel which automatically positions and sizes controls based on space availability within the frame.

Hey Anthony,

I’ve needed to do something similar to what you described like this:

  • Layout all your controls down from #1-#10 vertically and set them all to be not visible.
  • Write a method that…
  • Set an integer, like ControlTopNext = the top of #1
  • Set the top of the first Control you want to be visible and set the top to ControlTopNext
  • Update ControlTopNext = ControlTopNext + first Control Height + the gap you want between controls
  • Set the top of the next Control you want to be visible and set the top to ControlTopNext
  • Then for each additional Control update the ControlTopNext and make the Control visible and set the top.

It sounds like a pain, but it’s not too tricky.

That’s actually a good idea. Basically create the controls and please them as needed using an incrementing variable to track them.

A variation on Hal’s method would be to have a VisibleControls array (or dictionary using control’s custom integer “Position” for keys) that you add and remove references to the controls in as events occur. Then after each (change) event you call a LayoutControls method that runs through the available controls and hides them if not in the VisibleControls array, or sets them visible and positions them at NextTop, setting NextTop to the newly positioned control’s Top + Height + Gap before checking next control.