In MainWindow, I have a toolbar with items like ‘Professors’ and ‘Students’. Based on the selection I create a window (e.g. ProfessorWindow or StudentWindow) based on MyWindow. MyWindow only contains one ListBox (ListBox1). By using a constructor on MyWindow, ListBox1 can dynamically be filled with the correct data, columns, headings…
Since ‘professor data’ can differ from ‘student data’, I built two ContainerControls (ContainerControl1 for ‘professor data’ and ContainerControl2 for ‘student data’). ContainerControl1 and ContainerControl2 contain labels and textfields.
dim ProfessorWindow As new MyWindow1(Title, Table, SqlStatement, Headings, Columns)
dim myControl As new ContainerControl1
This works fine! Now I want to update the Textfield data in e.g. ContainerControl1 with the data in ListBox when I scroll through the ListBox. I cannot use the change event from ListBox1in MyWindow since ContainerControl1 and Textfield1, Textfield2… are unknown. I can show the data from e.g. the first row when I add the following lines before the line ProfessorWindow.Visible=True
Dim row as Integer
This still works! But how can I react on a change event (scrolling trough Listbox1) to show the data of the second, third… row? The change event on ListBox1 has no idea of the Textfield data in e.g. the ContainerControl1. This change event cannot be used. Is there any way to solve this problem?
@Emile Schwarz To answer your questions: 1) I want to reuse the general structure of a window (in my case MyWindow1) and 2) use ContainerControls for displaying different data in the window (in my case ContainerControl1 for displaying ‘professor data’, ContainerControl2 for displaying ‘student data’). Both ContainerControls have a number of labels and Textfields. The number of labels and Textfields is not the same.
I understand your remark. This works perfect when ListBox and Textfields are defined in the same Window (e.g. MyWindow1). I want to make my code more versatile and try to reuse everything without redefining all kind of stuff.
Do not create the containers dynamically, use a page control and place a container on each page. Then show the required container by setting its value. Then you can access either container from your change event.
Create a variable of the base class and when you create your container assign it to the variable. In your change even is IsA to chech the container type.
Similar to the previous option, create a common interface for the container rather than use a base class.
@James Dooley No idea how I can realise your second suggestion. I will try to use a page control with ContainerControls on each page. This looks a little bit ‘tricky’. My problem is that I always refer to the Java language. But, XOJO is not Java!
@Kevin Gale @James Dooley Thank you, Kevin. I solved the problem by putting the containers in a page control (thank you James). Since I am just experimenting with XOJO to decide whether we will introduce XOJO to build real ‘big’ applications, I will test your suggestion in a few days. I keep you informed!
You can use AddHandler to send the event to a method in the window though I’m not sure that will get you to where you’re trying to go. Change won’t fire from scrolling, but cellBackgroundPaint will. It may fire more than you need though.
I would recommend adding events to the container that can be raised from the listbox using raiseevent. Then add the container to the window and handle the event in the event handler of the containerControl instance directly.
AddHandler is good if you don’t know the number and class of the containers until runtime and need things to be more dynamic.