Ok, I'm going to share this so it's easy for others.
Verified in 6
1) Create a new button. I'll call mine "My Default Column Behavior". I put mine in the mainstack, but the substack the rest of the DataGrid could work too, if you're going to go further in customizing your DataGrid
2) Add the following script.
Code: Select all
on FillInData pData
set the text of the long ID of me to pData ## temp workaround for
local tIndex, tDataOfLine, tTextStyle, tCol
try
put the dgIndex of me into tIndex
put word 1 to 2 of the short name of me into tCol
put getStyle(tIndex, tCol) into tTextStyle
set the textStyle of field 1 of me to tTextStyle
--if tTextStyle is not empty then answer tTextStyle
end try
end FillInData
on LayoutControl pControlRect
end LayoutControl
on ResetData
set the text me to empty
local tIndex, tDataOfLine, tTextStyle, tCol
try
put the dgIndex of me into tIndex
put word 1 to 2 of the short name of me into tCol
xStyle tIndex, tCol
set the textStyle of field 1 of me to empty
end try
end ResetData
on PreFillInData
local tIndex, tDataOfLine, tTextStyle, tCol
try
put the dgIndex of me into tIndex
put word 1 to 2 of the short name of me into tCol
xStyle tIndex, tCol
set the textStyle of field 1 of me to empty
end try
end PreFillInData
setprop dgHilite pBoolean
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
return the long ID of me
end dgDataControl
command EditValue
EditFieldText the long ID of me, the dgIndex of me, the dgColumn of me
end EditValue
on mouseDoubleUp pMouseBtnNum
if pMouseBtnNum is 1 then
if the dgProps["allow editing"] of the dgControl of me \
and the dgColumnIsEditable[the dgColumn of me] of the dgControl of me then
EditCellOfIndex the dgColumn of me, the dgIndex of me
exit mouseDoubleUp
end if
end if
pass mouseDoubleUp
end mouseDoubleUp
The base code for this can be had by using
set the script of button "My Default Column Behavior" to the script of button "Default Column" of stack "revDataGridLibrary". See
This Lesson on custom behaviors. You can use the Message Box for this if you wish.
3)Put this code in the script for your DataGrid
Code: Select all
local StyleGrid
function getStyle ind col
return StyleGrid[ind][col]
end getStyle
on setStyle ind col sty
put sty into StyleGrid[ind][col]
RefreshIndex ind
end setStyle
on xStyle ind col
put empty into StyleGrid[ind][col]
end xStyle
on clearStyle
put empty into StyleGrid
RefreshList
end clearStyle
4) Point your DataGrid to your new handler. Enter
set the dgProps["default column behavior"] of group "DataGrid 1" to the long id of button "My Default Column Behavior". You can use the Message Box for this if you wish.
5) Test it. I created a button with this script:
Code: Select all
on mouseUp
local tIndex, tColumn, tStyle
put "Col 1" into tColumn
put "bold" into tStyle
put the dgIndexOfLine[the dgHilitedLines of group "DataGrid 1" ] of group "DataGrid 1" into tIndex
dispatch "SetStyle" to group "DataGrid 1" with tIndex, tColumn, tStyle
end mouseUp
You can handle other behaviors this way -- background color is a good one. You just set up a bunch of variables to store the data.
It lets me change the formatting on the fly, and it keeps the formatting info out of the DataGrid. You can "Send" or "Dispatch" from any script to alter the presentation this way. You also do not have to worry about getting your formatting in your dgText.
It was also nice to find a way to not have to create a script for each column.