I have created a WebDialog with a WebListBox control amongst other controls.
I have created a number of subclasses from this that should pass in different parameters when instantiating the object.
To do this, I have done the following:
- Added a
Columns property to the WebDialog which stores the number of columns the WebListBox in the WebDialog should contain
- Added the constructor method to the WebDialog, which sets
Columns to the value passed in when instantiating the WebDialog
- Added an Opening event in the WebListBox to set
ColumnCount property to
Is the above the right approach in Xojo web app?
Also, when dragging the subclass WebDialog object into the shelf, there’s no way to pass in constructor parameters? Does that mean I have programmatically instantiate the WebDialog?
I typically put a property in the WebDialog for an array not a property for WebListbox column count. I use a Session property like MyDialog for the MyWebDialog and then when I need to instantiate it I just create a new dialog like:
Session.MyDialog = New MyWebDialog
Session.MyDialog.arrayname = somevalues
Then on Shown I populate the WebListbox from the Array Values using the Array two dimensional values to set the column count. No additional constructor needed.
Edit: Actually you need to set the column widths in the WebListbox opening event from the arrayname.LastIndex(2) adding 1 to the zero based last index and then in the shown event populate it from the array.
Ok thanks. Just to check I understand what’s happening:
I would need to instantiate the WebDialog when first needed, stored as a property of the Session e.g. MyDialog. I could then return a database query and store the rowset as a property of MyDialog e.g. myarray.
Then when I need to show the WebDialog, I would call the Session.MyDialog.Show. This would then trigger the Shown event of the WebListBox control inside MyDialog. The Shown event would contain code that loops through rowset and populates itself. Therefore, I don’t need to explicitly state the number of columns as it’s inferred from rowset dimensions?
Is my understanding above all correct? And I take it by instantiating the WebDialog as a session property, this will be in scope of any methods in any Pages?
Also, why would I need to set column widths of the WebListBox if that is drawn to size in the WebDialog.
Widths was a typo. I meant ColumnCount. You can’t set ColumnCount dynamically except in opening in 2022R2.
By creating the session property you only instantiate the WebDialog when you need it. When you close the dialog it goes out of scope.
Since 2022R2, you can modify the ColumnCount at any time
I tried doing this, but there’s an issue. Before you assign array/rowset values to arrayname, you have to instantiate MyWebDialog. By instantiate it, the opening and shown events of the WebListBox are executed and therefore it attempts to populate the WebListBox by reading myarray, before myarray is even set.
I have had to make myarray a property of the WebPage so I can write the rowset to it, before instantiating MyWebDialog. Let me know if that’s best.
That is correct. You have to do your query and populate the array before you instantiate the Dialog, but you do that all in one code block.
Var sqlselect As String = ("SELECT something from something...")
// Query Database with predefined Method
session.dbArray = Session.DBReturnRecordSet2D(sqlselect)
// Launch the Dialog and populate the array
Session.MyDialog = New MyWebDialog
Session.MyDialog.MyArray = Session.dbArray
Thanks that helps a lot. Just on a side note, does it matter if I store MyDialog as a property of a WebPage or does it have to go in Session? Is there a benefit of one over the other e.g. useful to put in Session if I have multiple WebPage, otherwise I can place in a WebPage if I only have one WebPage in the app?
I would tend to think it would be better to always reference dialogs through a session property over one in a web page to prevent having to refactor your code if you later add pages to the app. But I can’t say if that is a definite best practice. Maybe someone else will weigh in with a supporting or differing opinion that they can justify.
For me I heavily rely on the session model for Properties and Methods because I expect my users to be performing the same actions simultaneously. I really think a lot about can safely be done within the web page context, but It is much less used than my Session code.