Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
jameshale wrote: Sun Nov 24, 2019 7:54 amWhy not download the trial of DGH and see what it can do.
I did, about a year ago, and the experience was so painful I swore never to try again. DG gets a lot of flak on this forum, but to me DG Helper was even worse.
Data Grid was grafted onto LiveCode rather than being built in as native. Data Grid Helper is grafted onto Data Grid. Duct tape onto existing duct tape.
Regular LC fields are OK - and very convenient to use - unless some buttons or icons are needed in lines.
Concerning my problem of how to change the background of a cell from another cell, I just realized I put a Option Menu button, and a checkbox in a Table DG... Maybe it's the reason why I don't understand FourthWorld's script?
I have a column named "active". That column contains a checkbox named "Check".
This is the script of the button "active behaviour":
on mouseUp pMouseBtnNum
if (pMouseBtnNum = 1) then
put the short name of me & "---" & the owner of me & "---" & the owner of (the owner of me) & "---" & \
the owner of (the owner of (the owner of me))
--> active 0001---group "active"---group "dgList"---group "dgListMask"
on mouseUp pMouseBtnNum
if (pMouseBtnNum = 1) then
put the short name of the target & "---" & the owner of the target & "---" & the owner of (the owner of the target) & \
"---" & the owner of (the owner of (the owner of the target))
--> Check---group "active 0001"---group "active"---group "dgList"
I don't see useful parent reference there, once again, maybe it's because I use a table DG.
Ah yes, there is a section “ How Do I Customize a Table's Columns?”
The embarrassing thing here is that I compiled all the DG lessons into the guide, updating the screen dumps and instructions to reflect LC 8’s new interface a few years ago and completely forgot this section existed.
In doing the compilation I did of course have to complete each example in order to a) make sure it worked and b) obtain the screen shots.
As Homer would say “doh!”
As usual, that DG lesson raises more questions than it answers. Plus, it didn't work for me.
(1) For some reason, to create a column TEMPLATE, instead you click column BEHAVIOR. Is a template the same thing as a behavior? If not, then what's the difference? And why are we clicking BEHAVIOR to create a TEMPLATE? No clue.
(2) When I click to create a new Column Behavior, my screen looks completely different from the screenshot. My template group is several lines high, it's pretty wide, and the label is all the way on the right. Does this matter? Should I try to resize my template group to be only 1 line high if I want it to be only one line high in the DG? No clue.
(3) I drag a checkbox into the template group area, then try to close the template group editing window. I'm surprised that I'm prompted to Save the stack. Of course this isn't mentioned in the lesson. So I save the stack so I can close the template group editing window. But after saving, the editing window is still open. Ugh. Close the window again, this time it closes without complaint. But my checkbox doesn't appear in the DG. Is it because there's no data in the DG? I add some, still no checkbox. I decide to go back to the template group editing window to make sure the checkbox is still there, but this time when I click the Column Behavior button, instead of showing me the template group editing window, I see a script editor window. No clue how to get back to the template group editing window.
(4) Okay, I'll delete the DG and start over. Of course that doesn't work either: A bug in the IDE means that no DG appears when I drag it out of the toolbox. Restart LiveCode and start over again from scratch.
(5) Create a new stack, create a DG, add two columns, populate, and Save so I can restart from here after the next inevitable roadblock. Follow the instructions again and see that I missed that I'm supposed to do Edit Group twice for some reason that's not explained. Do that, but then it's the end of the instructions. No clue how to add a button, except for the unhelpful, "At this point you can customize what controls appear in the column template." With no better ideas, I drag a checkbox on top of the column label. Try to close the editing template, and again for some reason I'm prompted to save. Click Save, and then THE IDE CRASHES, stuck on the "Saving..." box forever.
This is why people hate the DG and the documentation. I hope someday LC makes a DG-type control that's native rather than grafted on, with LC-style syntax rather than its own special syntax, and intuitive operation rather than column behavior row template gobbledegook.
Zax, here's a script that kind of does what you ask, but there are lots of caveats.
This script goes in the COLUMN BEHAVIOR for the column that has the checkbox. You'd think that you'd be attaching the script to the checkbox, because that's logical. You'd be wrong.
on mouseup
put the dgHilitedLines of me into rowNumber
if rowNumber < 10 then put 0 before rowNumber
if rowNumber < 100 then put 0 before rowNumber
put 0 before rowNumber
put "Col 1" && rowNumber into col1
set the opaque of fld col1 to true
set the backgroundColor of fld col1 to "lightgreen"
end mouseup
Caveats:
(1) Code assumes that the checkbox isn't in column 1.
(2) Cell gets colored when the checkbox is clicked, regardless of the state of the checkbox. Normally you'd check the state of the checkbox with "if the hilite of me...", but because this is the Data Grid, that doesn't work. ("Object does not have this property.") I can't figure out how to test for the state of the checkbox.
(3) Manually coloring fields comes with a big problem if the DG is ever scrolled: Row 1 is always the first *visible* row, not the first physical row. So if you color a cell in physical row 1, then scroll, and the first visible row is now physical row 5, then physical row 5 is colored. The way you're *supposed* to colorize cells is dynamically with the FillInData handler, but this is enough head-banging for me for one evening.
MichaelBluejay wrote: Tue Nov 26, 2019 5:14 am I hope someday LC makes a DG-type control that's native rather than grafted on, with LC-style syntax rather than its own special syntax, and intuitive operation rather than column behavior row template gobbledegook.
I have a dream...
This is what I finally did (its's not perfect):
I have a column named "active", that contains a checkbox named "check". I wanted to change text color of a column named "name".
-- synchronize the hilite of the checkbox with the "active" data (0 or 1)
on FillInData pData
set the hilited of button "Check" of me to (pData = 1)
end FillInData
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 "Check" of me to false
end ResetData
on mouseUp pMouseBtnNum
if (pMouseBtnNum = 1) then
if (the short name of the target = "Check") then
if (the hilite of the target) then
SetDataOfLine the dgLine of me, "active", 1
else SetDataOfLine the dgLine of me, "active", 0
end if
end if
end mouseUp
-- change color, depending on the value (0 or 1) of the column "active"
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 setTextColor
end dgHilite
private command setTextColor
if (GetDataOfIndex(the dgIndex of me, "active") = 0) then
set the textcolor of me to "#999999"
else set the textcolor of me to black
end setTextColor