Removing containercontrol programmatically

I was working on a snippet that would show/hide containercontrols based on certain menuitem being checked or not. The embedwithin -part was easy but I spent quite a while trying to figure out how to hide it after the cc has been embedded. Is there any more elegant way to do this and where does the weird come from? Why isn’t the the same string that the IDE shows?

if config.pShowWorkspace then
    dim workspace as New workspaceCC
    for i as integer = 1 to self.ControlCount
        if self.control(i-1).name = "_workspaceCC.workspaceCC" then

I don’t know if this will help, but what I do is keep a reference to the container control after I have created it and embedded it, you could use an array or dictionary if you want to store it with a key that makes sense to your application.

To try and answer your question about the name, I am going to also guess that the container control name is not the same as the one on the IDE because you have created a new instance of it, suppose you created two instances, both having the same name would not be helpful.

I don’t know if this is what you are looking for… But here’s what I do…

[code]For i as integer = me.ControlCount-1 DownTo 0

if me.ControlAtIndex(i) isA WebContainer then
Dim TheContainer as WebContainer = WebContainer(me.ControlAtIndex(i)
//If you use an IF statement to identify what container you wish to remove, here you can test for it.
// For Example: If TheContainer.delete = true then
// Otherwise this is going to delete all controls that are WebContainers
TheContainer = false
end if

next i[/code]

Notice the .close is commented. I got some unexpected weird behavoiour if I do the close. For now i just make em invisible and forget they exist.

Doing this with normal container controls (None Web) Should be simple…

Hope it helps!

I hope this helps. It is the way I found to add and remove container controls for a project of mine. When I add a cc I keep a reference in an array as follows. I use this array to remove instances of the cc.

dim cc As new CoCRowContainer cc.EmbedWithin(self, RowLeft,Row1Top+(CoCRowContainer.Total-1)*RowSpacing) ... ccs.Append cc

To remove cc(s) I do the following. Note that in this case my cc contains a check box to indicate that it should be removed. Substitute whatever applies in your case. Total is maintained in the Constructor and Destructor methods for the cc. This seems to work without any problems. I use this regularly in my work.

dim i as integer if CoCRowContainer.Total>0 then for i=ccs.Ubound to 0 step -1 if ccs(i).RemoveSample.State=CheckBox.CheckedStates.Checked then ccs(i).close ccs.remove i end if next end if

Thanks all, I ended up keeping a reference of each cc as a property on the window. It also covered the next issue which was accessing methods and propeties on a cc.

If I’m correct:


should have been:



In a desktop app (Web apps are different) control(i) for a container is a placeholder, not the actual container. You should keep your own list as was recommended.

I’m working on a Desktop app and following code works fine in my app.

Dim ccAC As New ccAdmComp
// Remove EmbedWithin ContainerControl Screen(s)
For i As Integer = 0 To WindowMain.ControlCount - 1
    Select case WindowMain.Control (i).name
    Case "_ccAdmComp.ccAdmComp"
        WindowMain.Control (i).Close
    Case "_..."
    End Select

You’re relying on undocumented behavior. Just fyi. There is a better implementation floating around the forum somewhere. I’ll see if I can dredge it up.

Much appreciated.
Thank you Tim.

Here’s a post from the old forum.

Thank you very much Tim.
I will try this function.