Hello All,
i am bind a datatable to ultrawingrid. In that one of the columns is seconds, it shows as 2.6 seconds.
Now my application support localisation. When i use de-DE (german) with ',' (comma) as the delimiter and apply it in the initialize layout of the grid, it does not reflect the comma.
And also i have one more column which is a date format with milli seconds in it. Even this column does not display comma. Now when i export the grid data to an excel, i am able to see the comma, but that is only in the date column.
Now how can i make that comma visible
a. First of all in the grid for the seconds column
b. And also remove the comma when exported to excel.
Please let me know
Bobby
Hi Bobby,
The format of any particular cell in the grid depends on the DataType, the editor, and the Format property.
What is the DataType of the column?
Are you setting Format?
rac1719 said:When i use de-DE (german) with ',' (comma) as the delimiter and apply it in the initialize layout of the grid, it does not reflect the comma.
I'm not sure I understand you. What exactly are you setting in the InitializeLayout? The current culture? InitializeLayout is much too late to set the the culture for your application. This sort of thing should be done in the Main method of the constructor of the form. Or even the Form_Load. It needs to be established before the controls paint.
The format in Excel once again depends on the Format of the cell and the data type. I don't beleive there is any way to localize a particular Excel file - it uses the current culture of the operating system.
Excel Formats are not the same as DotNet formats (or at least not always the same). So the WinGrid exporter does not make any attempt to copy the grid column format into Excel. If you want to do this, you should use the InitializeColumn event of the UltraGridExcelExporter.
Thanks for the information Mike,
In the grid the data type for the decimal column is string, however for SortComparer I am using a ComparerClass(implemented by IComparer) which does the sorting considering the datatype as double.
In the initialize layout event for the grid I am saying
band.Columns["date"].Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " HH:mm:ss.f";
band.Columns["date"].MaskInput = "{LOC}" + CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " HH:mm:ss.f";
However for the decimal column I am using like this
band.Columns["decimalcolumn"].Format = ”d”;
Now when I apply the german localization with comma delimiter
Yes I do have InitializeColumn event for the export where doing other which is not related to these two columns.
Hi,
rac1719 said:In the grid the data type for the decimal column is string
The Format property works by calling the ToString method on the cell's Value and passing in the format. The string data type doesn't support any format strings, so you cannot format a string.
Why store numeric values as strings? This is going to cause you all sorts of problems. You have already dealt with sorting, but now you are having trouble formatting. You will also have trouble with filtering if you decide to use that. And exporting will be a problem because once again the value will be written to Excel as a string and Excel won't be able to format it as a numeric value, either.
Hello Mike,
Actually there is a requirement for this situation that when the duration value is 0 i need to show * in the display. So for this very reason i have changed the datatype of the column to string, so that when the value is zero i can make it as star.
Is there a way to have the datatype of the column as decimal and show '*' when value is 0
Please letme know :)
rac1719 said:Yes the asterisk has to be shown when its not in edit mode with red color.
If it's only when not in edit mode, then I'd go with the CreationFilter to change the text to whatever you want.
For the color, you don't even need a CreationFilter, you could just use the InitializeRow event and set the cell.Appearance.ForeColor.
rac1719 said:And also when the grid data is exported to excel the decimal value which we were talking till now should be shown as 3,6 for(3.6) in the German Culture and also if possible the time present in the date field should also be shown with a comma.
I'm not sure I understand what you want here. If the value is exported as a numeric value, then it will be formatted by Excel. The grid has no control over that - Excel does the formatting based on the ExcelFormatStr you set. I assume that the formats use the system settings for digit separators, so it will use a comma on a machine that is set up to use German settings.
Are you saying that you want a 0 to export as 3,6? That doesn't make much sense to me, but if that's what you want, you could do this in the CellExported event of the UltraGridExcelExporter. Just write whatever value you want into the Excel cell.
Yes the asterisk has to be shown when its not in edit mode with red color.
And also when the grid data is exported to excel the decimal value which we were talking till now should be shown as 3,6 for(3.6) in the German Culture and also if possible the time present in the date field should also be shown with a comma.
This is supposed to be in the OnInitializeColumnDataExcelExporter and the code i have there is
if (!string.IsNullOrEmpty(e.Column.Format))
{ e.ExcelFormatStr = e.Column.Format; e.ExcelFormatStr=e.ExcelFormatStr.Replace('f', '0');}
Is there anything to be added........?
If that's all you need, then you could achieve that must more easily using a CreationFilter or a DataFilter without all the problems that storing numeric values as strings will create.
Does the cell only have to show an asterisk when it's not in edit mode, or do you want the asterisk while the user is editing.
If it's the former, then the CreationFilter is probably the way to go. You can change the Text of the TextUIElement in the cell without affecting the actual cell value in any way.
If you need the cell to show the asterisk while in edit mode, then the DataFilter is better, but you will have to translate it in both directions (EditorToDisplay and DisplayToEditor).