Formatting a currency amount in a data grid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Formatting a currency amount in a data grid

Post by phaworth » Wed Jul 29, 2009 1:55 am

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

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Wed Jul 29, 2009 3:25 pm

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
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 29, 2009 5:29 pm

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

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Wed Jul 29, 2009 5:44 pm

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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 29, 2009 5:51 pm

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

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Wed Jul 29, 2009 6:21 pm

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
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Wed Jul 29, 2009 7:13 pm

Thanks for this great information Trevor. The API docs really help bring everything together in one place.

Pete

Post Reply