How to create/use controls at runtime

Yesterday I did some tests to add and use a DesktopListbox at runtime on a dynamic created DesktopWindow at runtime. The problem seems very straightforward. However, I spent at least an hour looking into why the data in the ListBox was not showing. The fact that I didn’t add the DefaultRowHeight statement was the culprit. I want to share my experiments with all readers of this forum:

//Create new window from DestopWindow
Var w3 As DesktopWindow= new DeskTopWindow
w3.Type = DesktopWindow.Types.Document
w3.Title = "Test"
w3.Top = 200
w3.Left = 400
w3.Height = 500
w3.Width = 800
w3.Visible = True

//Create new Listbox
Var s As DesktopListbox = New DesktopListbox
s.Enabled = True
s.HasBorder = True
s.HasHeader = True
s.GridLineStyle = DesktopListbox.GridLineStyles.Both
s.Left = 20
s.Top = 20
s.Height = 200
s.Width = 600
s.ColumnCount = 2
s.DefaultRowHeight = 20 //Data will not be shown without this statement!
s.Visible = True
w3.AddControl(s) //Add Listbox to Window

//Add Data
s.HeaderAt(0) = "col0"
s.HeaderAt(1) = "col1"
var items() As String
items.add("test1")
items.add("test2")
s.AddRow(items)
items.RemoveAll
items.add("test3")
items.add("test4")
s.AddRow(items)
w3.Show

To save valuable time it would be very useful to provide, for each control, the list of properties that are required during the creation of a control at runtime.

in autocomplete a necessary symbol?

I don’t think so…

a minimumInitialization method, somehow as we drop a control into form designer?

or like this?

Var s As DesktopListbox = DesktopListbox.createElement()

to add/support better framework documentation by community was already made.

that a new object starting by default with all values 0, boolean false, strings “” is ok.

It’s documented.

2 Likes

Indeed! But I didn’t find it… XoJo is a great language but the documentation is spread across the entire website. This makes it difficult to learn the language.

1 Like