Adding checkbox buttons from script

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Adding checkbox buttons from script

Post by PoLyGLoT » Tue Oct 17, 2017 1:32 pm

Hi,

I want to add checkbox buttons based on the numbers of columns in a file. I have a button to import a file, and based on the contents of that file, I want to be able to create, say, 15 checkbox buttons with the titles reflecting information from the file. Note that the # of buttons I need and the titles of those buttons will change with each new file I import.

Can you add checkbox buttons from the script? Or do you have to put them there in developer mode?

If you cannot add them from the script, is it possible to add a bunch of buttons at the beginning and then change the titles later from the script?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Adding checkbox buttons from script

Post by dunbarx » Tue Oct 17, 2017 2:05 pm

Hi.

LC can do anything you can think of. Check out the "create" command in the dictionary.

In your script, you would (pseudo)

Code: Select all

create button
set the style of last button to "checkBox"
set the loc of last button to wherever
set all other properties you are interested in
Craig Newman

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Adding checkbox buttons from script

Post by Mikey » Tue Oct 17, 2017 2:11 pm

Yes, you can.
Things to check in the dictionary:
  • "button" for all the button properties that you can set
  • "style" is the property that controls the type of button (rectangle, checkbox, etc.)
  • "templateButton". You can preset all the properties that you want all your checkboxes to share, before you create them

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Adding checkbox buttons from script

Post by PoLyGLoT » Tue Oct 17, 2017 3:14 pm

Thank you both.

I can create the buttons now, but I am trying to have them appear in a column within a text field.

Is it possible to take a set of text lines, and using a repeat function, transform a text line into a checkbox button? This would work better for my purposes.

Basically, I have this in a text field:

Code: Select all

Username
ID
ExperimentName
Session
Trial
Date
It's organized the way I want. I want to first populate the text field with all the info I want, and then transform those text lines into checkbox buttons. Is that possible?

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Adding checkbox buttons from script

Post by Mikey » Tue Oct 17, 2017 3:18 pm

You could with a datagrid. That would also give you a scroller, without having to build everything.

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Adding checkbox buttons from script

Post by PoLyGLoT » Tue Oct 17, 2017 3:23 pm

Just looking at a data grid and it seems like exactly what I want! Thank you!

Once I import the data into the grid, is there anything special to turn the row into a checkbox? Or can you make just the first column a checkbox, and the other columns pure data. That might be good for my purposes, actually.

Anyways, thank you!

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Adding checkbox buttons from script

Post by Mikey » Tue Oct 17, 2017 3:25 pm

I would go even simpler than that and just use the first column as a text field and control it so that it either has an “X” or is blank.

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Adding checkbox buttons from script

Post by PoLyGLoT » Tue Oct 17, 2017 4:11 pm

I have created a data grid with two columns, but I cannot figure out how to make the first column a text column (or a checkbox):

Image
Attachments
datagrid.JPG
datagrid.JPG (25.21 KiB) Viewed 6084 times

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Adding checkbox buttons from script

Post by Mikey » Tue Oct 17, 2017 4:20 pm

It should already be a text column. Now refer to the DataGrid manual. You can either respond to a click on a row, or a click in the "Selected" column on a row (I prefer to respond to a click anywhere on a row, but that's just my preference). When someone clicks on a row in that column, the value of the cell should toggle between "X" and empty.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Adding checkbox buttons from script

Post by dunbarx » Wed Oct 18, 2017 4:31 am

If you use a DG for your purposes , you will likely need to use the "form" variant, as opposed to the more basic "table" type.

DG's, especially forms, require a learning and practicing curve. They work right out of the box, but to customize them takes time.

It is time well spent, as they are powerful tools once you become even moderately proficient.Check out the lessons and the DG manual, as Mikey suggested.

Craig Newman

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Adding checkbox buttons from script

Post by Mikey » Wed Oct 18, 2017 11:53 am

I don't think in this case form is necessary since you can fake checkbox behavior, but if it isn't good enough, then I agree, form

Post Reply

Return to “Talking LiveCode”