Page 1 of 1

Changing text properties in a datagrid

Posted: Sat Nov 21, 2009 8:28 am
by phaworth
Is it possible to set a line of text in a datagrid table to bold in a script. In other words the text would be left at default when defining the datagrid properties but be set to bold in some lines by a script depending on data conditions.
Thanks,
Pete

Re: Changing text properties in a datagrid

Posted: Sat Nov 21, 2009 8:43 pm
by sturgis

Re: Changing text properties in a datagrid

Posted: Mon Nov 23, 2009 6:03 pm
by phaworth
Thanks, that's what I needed.
Pete

Re: Changing text properties in a datagrid

Posted: Mon Nov 23, 2009 7:10 pm
by phaworth
Well I guess I spoke to soon!

The code I'm writing isn't executed from within the column behaviour scripts but as part of a button mouseUp event handler. It needs to be able to set all the text in certain lines in the datagrid to bold. It looks like it's the textstyle property that I need to use to get the bold setting but I can't figure out how to do that for the whole line. Do I ahve to set it for each column in the line individually and if so, how do I set about doing that?

Thanks,
Pete

Re: Changing text properties in a datagrid

Posted: Tue Nov 24, 2009 12:22 pm
by Janschenkel
I would add another, invisible column to your dgData array, let's call it "textStyle", and differentiate the column behavior on the basis of that entry.
Here's how I made a quick test stack for myself:
- create a new stack
- drop a datagrid onto it
- give it 4 columns
- for the first column, add a column template
- leave the template as is, but change its column behavior script, updating the FillInData handler to:

Code: Select all

on FillInData pData
   local tDataGrid, tIndex, tDataOfLine, tTextStyle
   put the dgControl of me into tDataGrid
   put the dgIndex of me into tIndex
   put the dgDataOfLine[tIndex] of tDataGrid into tDataOfLine
   put tDataOfLine["textStyle"] into tTextStyle
   set the textStyle of field 1 of me to tTextStyle
   set the text of field 1 of me to pData
end FillInData
- use the Content panel of the Inspector palette to quickly add a few lines to the datagrid
- drop a button next to your datagrid, and set its script to:

Code: Select all

on mouseUp
   local tDataOfLine
   put the dgDataOfLine[1] of group "Datagrid 1" into tDataOfLine
   put "bold" into tDataOfLine["textStyle"]
   set the dgDataOfLine[1] of group "Datagrid 1" to tDataOfLine
end mouseUp
- click the button, and 'lo and behold, the first column of the first row is now in bold
- as a bonus, you can use any valid combination of text styles, such as "bold,italic" and they will all be applied

Applying this textstyle-driven behavior script to each column, should do the trick.

HTH,

Jan Schenkel.

Re: Changing text properties in a datagrid

Posted: Tue Nov 24, 2009 6:20 pm
by phaworth
Excellent, thanks Jan.
Pete