I have a Table style datagrid.
In my app I'm going through the datagrid and trying to update a database based on the contents of a cell in the table.
I'd like to hilte a cell in some way if the update fails. Something like make the text bold or set the background to red.
What would be the easiest way to accomplish this?
Hiliting a cell in a datagrid [SOLVED]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Hiliting a cell in a datagrid [SOLVED]
Last edited by bcmadore on Thu May 09, 2013 11:56 pm, edited 1 time in total.
Mac OS X 10.5.8 PPC | Mac OS X 10.6/7/8 Intel | LiveCode 5
Re: Hiliting a cell in a datagrid
Hi.
I see nobody has touched this. I use datagrids, and still do not understand them.
The "cell" you mentioned is really a field, named according to its row and column position, as in field "Col 2 0002".
So you can always set field properties, either by using "the target" if you click on a cell, or by referencing the field directly:
set the textStyle of the target to "bold"
set the textStyle of fld "Col 2 0002" to "bold"
That sort of thing
Craig Newman
I see nobody has touched this. I use datagrids, and still do not understand them.
The "cell" you mentioned is really a field, named according to its row and column position, as in field "Col 2 0002".
So you can always set field properties, either by using "the target" if you click on a cell, or by referencing the field directly:
set the textStyle of the target to "bold"
set the textStyle of fld "Col 2 0002" to "bold"
That sort of thing
Craig Newman
Re: Hiliting a cell in a datagrid
Trying:
in a button sets the text style of the button pretty well.
Trying:
(zero format pads the leading zeros on the number)
instead of set the textStyle of the target to "bold" does two strange things.
1) Sets the text style of multiple lines
2) Fails after a certain number of lines
I can almost touch a solution...
Code: Select all
put "Col 2" into theColumn
put the dgHilitedLine of grp "dgTest" into theLineNo
put theColumn & comma && theLineNo & cr after fld "debug"
dispatch "EditCell" to grp "dgTest" with "theColumn, theLineNo"
set the textStyle of the target to "bold"
Trying:
Code: Select all
local fldName
put theColumn && zeroFormat(theLineNo) into fldName
set the textStyle of fld fldName of grp "dgTest" to "bold"
instead of set the textStyle of the target to "bold" does two strange things.
1) Sets the text style of multiple lines
2) Fails after a certain number of lines
I can almost touch a solution...
Mac OS X 10.5.8 PPC | Mac OS X 10.6/7/8 Intel | LiveCode 5
Re: Hiliting a cell in a datagrid
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.
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
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:
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.
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
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
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
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.
Mac OS X 10.5.8 PPC | Mac OS X 10.6/7/8 Intel | LiveCode 5