Creating a CheckBox with code

I am working on a desktop project where I would like to create a CheckBox using code when a file is opened. What I have so far is the following:

[code]
dim FileCheckBox(10) as CheckBox

FileCheckBox(FileCount) = New CheckBox

FileCheckBox(FileCount).Caption = OpenFile.name //OpenFile is a folder item

FileCheckBox(FileCount).left = 380
if FileCount = 0 then
FileCheckBox(FileCount).Top = 40
else
FileCheckBox(FileCount).Top = (20*filecount)+40
end

FileCheckBox(FileCount).enabled = true
FileCheckBox(FileCount).Visible = true
FileCheckBox(FileCount).value = true

FileCount = FileCount +1[/code]

Nothing appears when I run the program yet, from debugging, I can tell that the folder item is coming in correctly. What am I doing wrong?

As always, a thousand thank yous!

You need to use a control set of checkboxes on your window. Drag a checkbox on your window, name it FileCheckBox, in the inspector select the gear icon and change the Member of to New control Set. Then you can either duplicate the control on the window or create instances in code.

[quote=209293:@Meade Lewis]I am working on a desktop project where I would like to create a CheckBox using code when a file is opened. What I have so far is the following:

dim FileCheckBox(10) as CheckBox
  
  FileCheckBox(FileCount) = New CheckBox
  
  FileCheckBox(FileCount).Caption = OpenFile.name //OpenFile is a folder item
  
  FileCheckBox(FileCount).left = 380
  if FileCount = 0 then
    FileCheckBox(FileCount).Top = 40
  else
    FileCheckBox(FileCount).Top = (20*filecount)+40
  end
  
  FileCheckBox(FileCount).enabled = true
  FileCheckBox(FileCount).Visible = true
  FileCheckBox(FileCount).value = true
  
  FileCount = FileCount +1[/code]

Nothing appears when I run the program yet, from debugging, I can tell that the folder item is coming in correctly. What am I doing wrong?

As always, a thousand thank yous![/quote]

To create checkboxes dynamically, make one a Control Set (in the gear part of the Inspector), then you will be able to create new members at will.

[code]  dim c as new CheckBox1

I think this is covered quite well in Paul’s Webinar:

http://www.youtube.com/watch?v=cje6etv42_Y&feature=youtu.be

(Source code in the Xojo Examples folder I believe.)

Curious why it is you want to do this rather than already have one present & just make it visible or not ?

Because I am interested in creating the RadioButton as it is needed. Potentially hundreds of them could be created.

That wasn’t clear
If thats the case see the webinar about creating controls instances on the fly Doug mentioned

[quote=209355:@Norman Palardy]That wasn’t clear
If thats the case see the webinar about creating controls instances on the fly Doug mentioned[/quote]

Sorry for the lack of clarity. Thanks Norman, I appreciate it.

I was really just check ing if you really needed to create them dynamically - but since you say there could be many that sounds like a requirement.

Yeah, dynamically creating the UI for this project seems like an inevitable requirement. Thank you so much Norman! I always appreciate your input and wizardry!