Create n New Object instances on the fly to embed in a ListBox

So I was searching for how to have a checkbox in a listbox and came across this thread: where Brock Nash posted an example of how to embed a checkbox in a listbox. So I’m wondering the best way to create an unknown number of embedded checkboxes using this technique so I can populate every row. What I’m stumped about is how to create all the necessary objects for n number of rows on the fly and increment the naming to match the rows.

Creating one is easy:

Dim cccb As CCCheckBox = new CCCheckBox cccb.EmbedWithin(session.CurrentPage, 0, 0, cccb.Width, cccb.Height) Me.cellPrependControl(cccb, 1, 0)

But how does one do something like this so that Xojo accepts the object names on the fly?:

For idx = 0 To ListBox1.RowCount -1 // create NEWOBJECTNAME from a base name incremented with the idx is the part I don't know how to do. i.e. cccb0, cccb1, cccb2, etc. Dim NEWOBJECTNAME As CCCheckBox = new CCCheckBox NEWOBJECTNAME.EmbedWithin(session.CurrentPage, 0, 0, NEWOBJECTNAME.Width, NEWOBJECTNAME.Height) Me.cellPrependControl(NEWOBJECTNAME, idx, 0) Next

I am probably missing something obvious or approaching the problem of populating an unknown number of objects wrong so please help me out here if you know how to fill my knowledge gap.

You don’t need a unique name for each one … make an array and keep a reference to each new instance in there. Declare a property to hold them all:

myCCCBs() as CCheckbox

maybe on the web page this is on

Dim cccb As CCCheckBox = new CCCheckBox
myCCCBs.append cccb
cccb.EmbedWithin(session.CurrentPage, 0, 0, cccb.Width, cccb.Height)
Me.cellPrependControl(cccb, 1, 0)

Note that you will have to manage this array (when one closes then you need to remove your reference in the array) - this won’t be done automatically.

DOH!
smacks forehead

Not to self: Go home at 5:00 or drink more coffee if the thinking is fuzzy…