Page 2 of 2
Re: Datagrid: changing cell style
Posted: Sun Nov 24, 2019 8:47 am
by MichaelBluejay
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.
Re: Datagrid: changing cell style
Posted: Sun Nov 24, 2019 9:13 am
by jameshale
I am sorry to hear that. I have found it invaluable.
There is even step by step instructions for adding controls to a column.
Re: Datagrid: changing cell style
Posted: Sun Nov 24, 2019 10:35 am
by Zax
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":
Code: Select all
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"
Now, with the following script:
Code: Select all
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.
Re: Datagrid: changing cell style
Posted: Sun Nov 24, 2019 7:04 pm
by MichaelBluejay
Zax wrote: Sun Nov 24, 2019 10:35 amI just realized I put a Option Menu button, and a checkbox in a Table DG...
I would love if you could tell me how you did that.
Re: Datagrid: changing cell style
Posted: Mon Nov 25, 2019 8:42 am
by Zax
MichaelBluejay wrote: Sun Nov 24, 2019 7:04 pmI would love if you could tell me how you did that.
I found infos there:
https://livecode.com/docs/9-5-0/compone ... data-grid/
Re: Datagrid: changing cell style
Posted: Tue Nov 26, 2019 12:40 am
by jameshale
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!”
Re: Datagrid: changing cell style
Posted: Tue Nov 26, 2019 5:14 am
by MichaelBluejay
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.
Re: Datagrid: changing cell style
Posted: Tue Nov 26, 2019 5:40 am
by MichaelBluejay
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.
Code: Select all
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.
Re: Datagrid: changing cell style
Posted: Tue Nov 26, 2019 10:42 am
by Zax
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".
In the "
active" column behavior script:
Code: Select all
-- 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
And in the "
name" column behavior script:
Code: Select all
-- 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
Re: Datagrid: changing cell style
Posted: Sat Feb 08, 2020 3:22 am
by guylouis
Hi,
I created an option button in a column of a DataGrid. OK, it reacts as I want.
I see there is a script for this option button with some handlers like "on FillInData pData", "on mouseDoubleUp pMouseBtnNum", .....
But how can I script this button to take an action when I click on it?
In a standard option menu, I can script this:
on mouseUp
... Take an action
end mouseUp
But this do not run on the button in the column DataGrid.
How can I do this?
Thanks
Re: Datagrid: changing cell style
Posted: Sat Feb 08, 2020 3:32 am
by MichaelBluejay
guylouis, please don't hijack existing threads for new topics. Please start a new thread for your new question.