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...
I don't think using a ValueList is the way to go here. It sounds like you want to do currency conversions so that the user sees a value expressed as one nation's unit of currency, while the underlying value is expressed as some other nation's unit of currency. The IEditorDataFilter interface was designed to handle this sort of requirement, as you can present one value to the user, and convert that value before it is committed to the cell's value.