Search code examples
vb.netformattinginfragisticsultrawingrid

Currency and decimal editor in Ultragrid


I have to format some of the datatypes for cell values of an ultragrid. I have used the DateTimeEditor for formatting the datetime values.

//Code

private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
{
   if (e.ReInitialize == false)
   {
       DefaultEditorOwnerSettings editorSettings;
       DateTimeEditor datetime_editor;
       string condition = e.Row.GetCellValue("Condition").ToString();
       switch (condition)
       {
            case "TEST1":
                editorSettings = new DefaultEditorOwnerSettings()
                editorSettings.DataType = typeof(DateTime);
                editorSettings.MaskInput = "mm/dd/yyyy";
                datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
                e.Row.Cells["DateInfo"].Editor = datetime_editor;
                break;
            case "TEST2":
                editorSettings = new DefaultEditorOwnerSettings()
                editorSettings.DataType = typeof(DateTime);
                editorSettings.MaskInput = "hh:mm:ss";
                datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
                e.Row.Cells["DateInfo"].Editor = datetime_editor;
                break;
       }
   }
}

Now, How can I format the currency and decimal values?

Is there any currencyeditor or decimaleditor?


Solution

  • You could use a EditorWithMask, but keep in mind that a column has a datatype and if your column datatype is not compatible with the expected Editor datatype the results are unpredictable

    EditorWithMask currency_editor;
    DefaultEditorOwnerSettings editorSettings = new DefaultEditorOwnerSettings();
    editorSettings.DataType = typeof(decimal);
    currency_editor = new EditorWithMask(new DefaultEditorOwner(editorSettings));
    editorSettings.MaskInput = "€ nnn.nn";
    e.Row.Cells["decimal_column_name"].Editor = mask_editor;