How to solve my problem?

Still trying to experiment with XOJO…

Let’s try to explain my problem:

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 myControl.Enabled=True myControl.Visible=True MyControl.EmbedWithin(ProfessorWindow,0,195) ProfessorWindow.Visible=True

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 row=0 MyControl.Textfield1.Text=ProfessorWindow.ListBox1.Cell(row,0) MyControl.Textfield1.Text=ProfessorWindow.ListBox1.Cell(row,1) ...

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?

Why ?
(This why denote that I do not understand the question. And what ContainerControls are used for ?)

In my project(s), when I want to display the contents of a Listbox Row, I use the Change Event, and Listbox1.ListIndex (if > -1) to do that:

If Listbox1.ListIndex > -1 Then TextArea1.Text = Listbox1.Cell(Listbox1.ListIndex,-1) // Copy the whole Selected Row contents into the TextArea End If

@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.

Three possibilities:

Do not create the containers dynamically, use a page control and place a container on each page. Then show the required container by setting it’s 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 I try to understand your second suggestion:

‘create a variable of the base class’: is this what you mean?

Dim myVariable as ContainerControl

‘when you create the container assign it to the variable’: Is this what you mean?


How can I now check the containertype in the change event of Listbox1? Since myVariable is local in a DropMenuAction of the toolbar in MainWindow?

[quote=418297:@Carlos De Backer]
How can I now check the containertype in the change event of Listbox1? Since myVariable is local in a DropMenuAction of the toolbar in MainWindow?[/quote]

Why would you even do that? You need to scope the variable appropriately level… at the window level I expect.

@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!

Maybe a class interface would work here?

  1. Create a class interface (iWindowContainer) with a single method (UpdateContents) with some parameters for the data.

  2. Your container controls would implement the interface with the relevant code to update the UI using the parameters.

  3. Your main window would have a property (mContainer_) of type iWindowContainer which you would set to your container control once created.

  4. Your listbox change event would call mContainer_.UpdateContents passing the relevant data.

I got the impression that your window was also assigning the initial values of the container control’s controls. I also recommend that the container control does that instead.

@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.