How to remove Controls?

Hi,

I have a Problem, I dont know how I could remove controls, that I added by code to my Webapp.

I have a ContainerControl, which I add to another ContainerControl 10 or 15 times. Now I want to remove all ContainerControls.

I tested it with ControlAtID, ControlWithName and the other. I builded a for i = 0 to … loop, but I don’t find the right way.

Could you help me?

When adding your container controls to the webpage (in code), keep an array with references to those instances within the webpage. Then you simply loop through that array and call containercontrol.close :slight_smile:

Okay!
But ( it sounds a little bit stupid) where can I add the Array?

I am from VB.NET, there I could Add it over the code in the Class, but in Xojo?

In the navigator on the left, right-click on your webpage, select “Add To WebPageXYZ” and then “Property”

hum,

thank a lot!

There is no datatype “Array” in Xojo like in VB, but I can save alle types as arrays?!

Dim names() As String names = Array("Fred", "Ginger", "Stanley")

I add the Controls over a loop into the Webpage (for i = 0 to whatever).
So I have to add the controls into the array also in the loop. But there’s no like Array.add(control). All controls I want to add must be known, when I add it to the array.

So, how can I add them, while I am doing the loop?

sorry for my english^^

Declare the property you just added to your webpage as follows: ThisIsAnArray() as MyWebContainer

The brackets indicate that this is an array of undefined size, fine for your purposes. Then in code, reference this array and append a container reference like this:

ThisIsAnArray.Append MyContainerInstance

Here’s a demo project: https://dl.dropboxusercontent.com/u/106712747/WebContainerDemo.xojo_binary_project

Yay! That works! last question:

how can I remove this controls yet? :slight_smile:

This is my Code, but it do not work…

if not main.Zentrale_Aktuell.Ubound = 0 then dim D as Post_normal for each d in main.Zentrale_Aktuell d.Close main.Zentrale_Aktuell.Remove(d.Index) next end if

Zentrale_aktuell is my Array with all Containers
Zentrale is the Container, where I add all other containers
Main ist my Webpage

The documentary is not really good.

Take a look at the example I linked, I gave it an update. There’s a button that removes the controls.

Uff!

Thank you very, very much!

It’s not really logical, how xojo in some details works, but anyway, it works!

For all user, here is the solution:

[quote] FOR i AS Integer = main.Zentrale_Aktuell.Ubound DOWNTO 0
main.Zentrale_Aktuell(i).Close
main.Zentrale_Aktuell.Remove(i)
NEXT[/quote]

What makes you believe it’s illogical? Maybe I can help you understand some bits and pieces.