Different Number formats for individual cells in a grid

BOster

BOster

Legendary Poster
Is there an *easy* way to have different number formats for an individual cell in a grid instead of the entire column? For example, some cells in a column may have commas and two decimal places and others may have no commas and zero decimal places.
 
Modifiable column?

If no then I can see it happening with a string data type and you format the string in a Write Grid Row Before event.
 
Modifiable column?

If no then I can see it happening with a string data type and you format the string in a Write Grid Row Before event.

Some columns will be data entry. I can still do a string and do my own parsing/validation for things like numbers etc., just didn't want to re-invent the wheel if there was a built in way to do it - some weird system function in a non-grid related category or something.
 
Just a follow up. I found strings would work with one BIG exception. You can't really right justify the numbers so things look really bad.

However, I found that if you are programatically filling the grid, you can call the system function SetDataDictionaryOverrides (this system function only takes a grid/column as args - no row arg) and specify a custom number format function the next line that gets inserted into the grid will have that number format and it will retain that format for lines being inserted until you call the system function again and change to a different format. I assume you could do something similar with a databound grid. I think though the key is to set the format before the line is inserted into the grid. I still need to do some more testing to see if there are any other problems but this may actually work.
 
Cool!
I was going to suggest that System function as I'd used it successfully on a generic grid I wrote before, but I thought it would only work for initialising the grid columns before it was loaded.

Great to know it works line by line too :)
 
Changing the DD item also works - I am using the C api SetGridColumnDataDictionaryItem, but I assume the ER system function equivalent would work the same way. Just have to call it before the grid record is written. The one downside is that any cells open for data entry, regardless of where they are in the grid, will display the number format at the time the grid record was written (which is what you want) HOWEVER, if you edit the value in that cell it will have the number format for the last call to the system function. In my specific case this is not a problem because all the data entry cells have the same number format so after the grid is loaded I make one final call to set the number format for data entry. Also, calling SetGridColumnDataDictionaryItem resets your column heading to the DD default so at the end you have to call SetGridColumnHeading to reset your column headings.

Other than those little quirks I think this might actually work.
 
Back
Top