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...
Hi,
You might also want to look at using an UltraNumericEditor for the cell editing instead of a plain old text editor. You can control the formatting of the cell to the user and maybe apply some masking to limit the number of digits\decimal places they are allowed to enter.
A good place to start is the samples, the ultragrid has many so it may be worth checking those out as well.
Hope that helps.
Andy
Hi, BBRail!
Thanks for your answer.
But my problem consists that I do not know as to display one value in a cell with format preservation, while in a cell the present value another. Formatting which offers EditorWithText, quite suits me
BBRail said: Hi, You might also want to look at using an UltraNumericEditor for the cell editing instead of a plain old text editor. You can control the formatting of the cell to the user and maybe apply some masking to limit the number of digits\decimal places they are allowed to enter. A good place to start is the samples, the ultragrid has many so it may be worth checking those out as well. Hope that helps. Andy