Page 1 of 1
Formatting a currency amount in a data grid
Posted: Wed Jul 29, 2009 1:55 am
by phaworth
I've been successfully using the ACcontingFormat() script to format currency numbers in a normal field OK but now I have some currency values in the data that is being retrieved from my SQLite database into a data grid, so the data is a long stream of characters with each column delimited by a tab and each row delimited by a return.
Short of looping through all of the data to reformat it as a currency value, is there another way to to do this?
Thanks,
Pete
Posted: Wed Jul 29, 2009 3:25 pm
by trevordevore
With data grids there is no need to format your raw data before assigning it to the data grid. A data grid allows you to customize how the data is displayed at the time it is displayed without affecting the underlying data stored in the data grid.
Take a look at the lesson "
How Do I Customize A Table's Columns?" (assuming you are using a data grid table).
In your case your custom column behavior might look something like this:
Code: Select all
on FillInData pData
set the text of field 1 of me to AccontingFormat(pData)
end FillInData
Posted: Wed Jul 29, 2009 5:29 pm
by phaworth
Thank you Trevor, that works just fine with one exception. The column is defined to be aligned right but the currency values in there are now aligned left in spite of that. Is there anywhere else that the column alignment is defined, other than in the column tab of the property inspector?
Pete
Posted: Wed Jul 29, 2009 5:44 pm
by trevordevore
Once you customize a column it is up to you to set alignment, etc. You can get the current setting of the column alignment using the dgColumnAlignment property. I believe the following should work in the FillInData handler.
Code: Select all
set the textalign of field 1 of me to the dgColumnAlignment[the dgColumn of me] of me
Alternatively you could just set the textalign of the field in your custom column group to "right" and not worry about the column alignment setting.
Posted: Wed Jul 29, 2009 5:51 pm
by phaworth
Thanks again Trevor.
There are so many undocumented areas of data girds right now, particularly in the dictionary. Are you aware of any source for the properties, messages, etc for data grids that would normally be on the dictionary?
Thanks,
Pete
Posted: Wed Jul 29, 2009 6:21 pm
by trevordevore
The majority of the data grid has been documented in the online manual that I maintain. I don't have control over the dictionary however.
The primary data grid manual is here:
http://revolution.screenstepslive.com/s ... s/datagrid
The chapter with messages, properties and API calls are available in the API chapter of the manual (this is where you find dgColumnAlignment):
http://revolution.screenstepslive.com/s ... apters/991
There is also a tips and tricks manual. There is a link to it from the main manual (in right column) but here is the link in case you are interested.
http://revolution.screenstepslive.com/s ... agrid_tips
Posted: Wed Jul 29, 2009 7:13 pm
by phaworth
Thanks for this great information Trevor. The API docs really help bring everything together in one place.
Pete