Handling data between containers

I have a testapp which looks like this:

1 Window.
1 container (which embeds 2 containers inside) placed on the window.

Now i want to transfer data from a textfield in container1 to a textfield in container 2.

I placed the event in the action of a button placed on container 1. But all i get is the following error:

Static reference to instance method: call this on an instance of class CustomerListview.CustomerListview.
CustomerListview.TextField1.Text = TextField1.Text

Can anyone explain how data is handled between containers?

On the instance of my container i cannot add an event to a control.

ok, this works:

WndTest.CustomerContainer1.CustomerListview1.TextField1.Text = TextField1.Text

The CustomerContainer1 is an instance of a container, which embeds 2 other containers (CustomerDetails and CustomerListview). The code above is placed in the Action-Event of a button placed on the CustomerDetails container.

I think it is advisable to design an interface on the level of containers. Hence, give your containers some methods that can be called from outside and do all the logic/data handling inside.
It’s maybe more work in the beginning, but you’ll end up with way clearer code and likely run less into problems when moving things around or renaming your controls.

I would very strongly advise against that design. The first thing you should do is set all your control scopes to private. This will make it impossible for one view to influence another.

Next, each view (window or container) should use methods for external sources to update their contents. This allows your view to change anything about what is inside it, without it breaking the code outside the view.

Finally, use event definitions to “push” data from a container to its parent. You use this to move data between containers. In your case, CustomerDetails should define a CustomerSelected event with a Text parameter. In CustomerDetails.PushButton.Action call RaiseEvent CustomerSelected(TextField1.Text). In CustomerListview, add a ShowCustomer(CustomerName As Text) method, which assigns the parameter value to TextField1.Text. Finally, in CustomerContainer1, implement the CustomerSelected event on CustomerDetails1 with CustomerListview1.ShowCustomer(CustomerName) and you are done.

What you’ve just done is made three pieces that “know” very little about each other. CustomerDetails and CustomerListview have absolutely no idea each other even exist. And this is good, because since they each exist in their own private world, they can change things with minimal consequences. CustomerContainer is the only piece that knows both exist, and even then, all it knows about them is what they want it to know. As long as CustomerContainer uses the methods and events the other containers define, it doesn’t need to care about how they do their work.

Designing this way is an exceptionally good habit to get into.

Thom, this sounds like a good approach. I will try this.