Hello, developers!
I was confronted by difficulties...
I have ultragrid. I use EditorWithText for every cell, for displaying formatting cell's data in dependency of it data.
(If cell value >= 1000, then I round off to integer: 14050.0234 = 14 050,
if cell value <1000 and >= 100, then I round to one decimal places: 925.441 = 925.4,
if cell value <100 and >= 10, then I round to two decimal places: 55.123 = 55.12,
and if cell value <10, then I round to three decimal places: 1.057923 = 1.057)
For example:
DefaultEditorOwnerSettings settings = new DefaultEditorOwnerSettings();
settings.Format = format; // Some format ("N0", "N1", "N2", "N3")
DefaultEditorOwner editorOwner = new DefaultEditorOwner(settings);
EditorWithText editor = new EditorWithText(editorOwner);
cell.Editor = editor;
In my case, I need select some foreign currency, and cell's data must be displaying data in selected currency.
On the one part, I need dislaying formatting value in grid's cells in accordance with selected currency, on the other part, i need save original value in Cell.Value
For example, I have cell.value = 125.02 (rubles), if i select USD (let 1 dollar = 30 Rubles), then cell must display 3 750 (125.02 * 30 = 3750.6) notably, I want display 3 750 (formatted value), but really cell value must be 125.02
I find partial solution of this problem - I use UltraGrid.DisplayLayout.ValueLists:
// In main form constructor
ultraGrid.DisplayLayout.ValueLists.Add("USD");
ultraGrid.DisplayLayout.ValueLists.Add("EUR");
ultraGrid.DisplayLayout.ValueLists["USD"].DisplayStyle = ValueListDisplayStyle.DisplayText;
ultraGrid.DisplayLayout.ValueLists["EUR"].DisplayStyle = ValueListDisplayStyle.DisplayText;
....
// in UltraGrid's InitializeRow event:
for(Int32 i = 0; i < grid.DisplayLayout.Bands[0].Columns.Count; i++)
{
UltraGridColumn column = grid.DisplayLayout.Bands[0].Columns[i];
if (column.Header.Caption == "Money")
// ValueLists
ValueListItem item = new ValueListItem();
item.DataValue = e.Row.Cells[i].Value;
item.DisplayText = ((double)item.DataValue * 30).ToString();
ugGrid.DisplayLayout.ValueLists["USD"].ValueListItems.Add(item);
settings.Format = //assign format;
editorOwner.MustDisplayFromList(column); // Display data from ValueLists
e.Row.Cells[column].Editor = editor;
break;
}
In this way, cell's data displaying in concordance with selected currency, but data's format is lose...
in concordance with our example, cell value will display 3750.6
What I do wrong?!
How i can find decision for this problem?
I will very grateful for any help, hint, example, link.
Thanks! :)
P.S.: I use NetAdvantage WinForms 10.1
Sorry for poor English...
There's a post here with some information about DataFilters.
Understanding IEditorDataFilter Convert functionality - Infragistics Community
And here's a simple DataFilter example:
HOWTO:Use a WinGrid DataFilter to convert strings to bools (and vice-versa) for a checkbox column
I attached a C# project that demonstrates how to use the IEditorDataFilter interface to present currency values to the user with the currency units of a specific culture, while maintaining the underlying values in USD.
Brian Fallon"] I attached a C# project that demonstrates how to use the IEditorDataFilter interface to present currency values to the user with the currency units of a specific culture, while maintaining the underlying values in USD.
Many thanks, Brian!
Your project's example very useful for me!!! Thanks!
Many thanks, Mike, for your links!
Hi Mike,
I have a similar problem. I have cell of type decimal formatted to ##,##. But when I got to the cell to edit the value I loose the
format and raw decimal value is showing up on select the cell. What is the way to avoid that?