How to put in a Checkbox into a Data Grid Table
and then center it
and it has no name.
First:
Do the documented process for creating a Data Grid and create your columns, including the one that is going to be a checkbox.
Once you have completed the Data Grid creation:
Go back to the Property Inspector and select the column you want to put a checkbox into.
1. Click on the '+' sign next to Column Behavior to create a column Behavior.
(do NOT subsequently click on the column behavior that shows up in the window)
2. Now click on the Data Grid tab in the Property Inspector.
3. Down at the bottom, click on Row Template.
4. This presents a window named Editing Template.
You will see the name of the column that you want to be a checkbox.
Make sure that "Select Grouped" item in the Toolbar is off.
Click on the column that you want to be a checkbox.
The entire area that is the "Row Template" will be "selected".
5. Now click on the Edit Group item in the Toolbar
(it will change its name to "Stop Editing")
6. Now click on the column item in the Editing Template window that you want to convert to a checkbox.
This time, that column item will actually be selected.
Delete it.
7. Drag a Checkbox in from the UI Palette or pick Checkbox from the Object Menu / New Control,
Placing it on the Editing Template window.
8. Click on the new Checkbox control.
You should see in the Property Inspector window that the title is now "Button Check".
IF the title on the Property Inspector window is NOT correct, make sure that the new CheckBox is selected, you might have to click on "Edit Group" again. But you need the correct title on the property Inspector before moving forward.
Change your focus to the Property Inspector.
In the Basic tab, change the Name back to the column name for the Checkbox.
If you want a Label, put it in - I did not.
If you do NOT want a label, click on "Show Name" to uncheck it.
Put in whatever Tooltip you want.
(there may be other things you want to change in the property inspector, that affect the button, do them)
(you also may be able to change the width of the Checkbox here to properly encompass what you want shown.)
(do NOT do SCRIPT things at this point!!!)
9. Change your focus back to the Editing Template window.
Change the size of the Checkbox so that it is properly sized. So for no title, just make it big enough for the Check box.
10. Click "Stop Editing" in the Toolbar.
(this stops editing of the templates)
11. Now you need that "Editing Template" window to go away.
Either close it, in which case you will need to save your stack.
Or save the stack and then close the window.
12. NOW we get into setting the Script for the Checkbox.
You will need a "Column Behavior" Script for this Checkbox button and getting such is not obvious (at least to me). If you don't put your script code into the proper place, it is never executed.
Open the Project Browser.
Expand the display of the stack you are working on (click on "+" sign)
You should see a "Data Grid Template" entry.
Expand it.
There are a number of cards displayed now - one for each Data Grid - and one more)
You will need to investigate each of the cards until you find one with the Column with the name of the CheckBox you just added.
Once you find the correct card, select the entry that is titled "checkbox name Behavior".
13. Control click on that Behavior entry and "Edit Script"
You will need to modify several of the commands / messages in this script.
FillInData, LayoutControl, ResetData.
Delete EditValue and mouseDoubleUp
Add mouseUp
Below is a possible set of methods for a checkbox:
In the following code, you only need to change the name of the column for the checkbox.
This code "centers" the location of the Checkbox in its column.
(Thanks to stam for that code and how to shut off the name of a Checkbox)
You might just completely replace all the methods in the "default" code with the following.
Double check that there has not been new features since I wrote this.
Code: Select all
-- This script defines the behavior of a table column's custom template.
on FillInData pData
-- This message is sent when the Data Grid needs to populate
-- this template with the column data. pData is the value to be displayed.
-- Example:
set the hilited of button 1 of me to (pData = "true")
end FillInData
on LayoutControl pControlRect
-- This message is sent when you should layout your template's controls if your template is a group.
-- If your template is not a group then there is no work to do here.
-- You can use items 1 through 4 of pControlRect as boundaries for laying out your controls.
-- The following code CENTERS THE CHECKBOX IN THE COLUMN
set the loc of btn 1 of me to the loc of me
end LayoutControl
on ResetData
-- Sent when column data is being emptied because the control is no longer being used to display data
set the hilite of button 1 of me to false
end ResetData
on PreFillInData
-- Sent right before new data is going to replace existing data in the column
end PreFillInData
setprop dgHilite pBoolean
-- This custom property is set when the highlight of your column template has
-- changed. You only add script here if you want to customize the highlight.
if pBoolean then
set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
else
set the foregroundColor of me to empty
end if
end dgHilite
getprop dgDataControl
-- Required by library so that it can locate your control.
return the long ID of me
end dgDataControl
-- Sent when the mouse is released after clicking
-- pMouseButton specifies which mouse button was pressed
on mouseUp pMouseButton
SetDataOfLine the dgLine of me, "NAME OF CHECKBOX COLUMN", the hilite of the target
end mouseUp