programmatically removing objects

andrewmp

Member
Licensed User
Longtime User
I'm programmatically adding objects to a panel using the addview command.

How can I programmatically remove ALL objects in the panel (the panel's children) after I've used them?

I tried using RemoveViewAt but I can't figure out how to get the index of the objects I added previously.

Is it possible? Can someone point me in right direction?

Thanks
 

andrewmp

Member
Licensed User
Longtime User
Solution

I figured it out:

For i=0 To Panel.NumberOfViews
Dim v As View

v = Panel.GetView(i)
If v.IsInitialized Then
If v.Tag ="formlabels" Then
Panel.RemoveViewAt(i)
End If
End If
Next

Thanks
 
Upvote 0

andrewmp

Member
Licensed User
Longtime User
RemoveViewAt

For i=0 To Panel.NumberOfViews
Dim v As View
v = Panel.GetView(i)
If v.IsInitialized Then
If v.Tag ="formlabels" Then
Panel.RemoveViewAt(i)
End If
End If
Next

Is not working properly, it does not remove all objects with the tag indicated.

Does anyone know what the index in RemoveViewAt() really refers to

i.e if I do this :

Panels.AddView(formlabels,0,x,120,40)
i=Panels.NumberOfViews

is "i" the index of the object added or does one get "i" in another way?

Thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You must use:
B4X:
For i = Panel.NumberOfViews - 1 To 0 Step -1
Because when you remove views the NumberOfViews property changes after each removing but the for loop tries to go til the original number.

Best regards.
 
Upvote 0
Top