Change ContainerControl Property from Window.Open event

I have a window populated with various labels and container controls.

They have place holders in their text/caption properties for a description
adjustable by user preference.

For example, a ‘Job’ may be a ‘Project’, ‘Event’, ‘Process’, ‘Gig’, etc.

What I’m trying to do is replace the place holder in the various controls when the window opens:

dim i As Integer for i = 0 to me.ControlCount-1 dim c As control = me.Control(i) select case c case isa Label dim l As Label = Label(c) l.Text = ReplaceAll(l.Text,"[J]",preferredJobDescription) // this case never runs: case isa myCC dim t As myCC = myCC(c) t.Caption = ReplaceAll(t.Caption,"[J]",preferredJobDescription) case isa EmbeddedWindowControl // IllegalCastException on this line: dim t As myCC = myCC(c) t.Caption = ReplaceAll(t.Caption,"[J]",preferredJobDescription) end select next i

I’m stumped how to access the property after I find the control.

You’ll have to keep your own array of the container controls. Containers are not accessible via Window.Control().

This turns out to be a perfect situation for a ‘Shared’ Property.

Add a dictionary to the ContainerControl:

Shared myControls As Dictionary

In the Container ‘Open’ event:

if myControls = Nil then dim d As new Dictionary myControls = d end if myControls.Value(self.Handle) = self

To keep things tidy, in the Container ‘Close’ event:

myControls.Remove(self.Handle)

Now it’s possible to access the control from the containing window:

dim i As Integer for i = 0 to me.ControlCount-1 dim c As control = me.Control(i) select case c case isa Label dim l As Label = Label(c) l.Text = ReplaceAll(l.Text,"[J]",preferredJobDescription) case isa EmbeddedWindowControl dim t As myCC // check to see if this is a myCC container if t.myControls.HasKey(c.Handle) then t = t.myControls.Value(c.Handle) t.Caption = ReplaceAll(t.Caption,"[J]",preferredJobDescription) end if end select next i