Hi,
I have a situation like this.
+ An ultragrid with currency column needs to be displayed with grouping separator, like this "12,345.50"
+ We use UltraCurrencyEditor as the EditorComponent for that column
gridLayout.DisplayLayout.Bands[visibleColumn.Band].Columns[visibleColumn.Key].EditorComponent = GetEditor(visibleColumn.Key, visibleColumn.DataType, false, false);
+ The currency editor is creating like below
UltraCurrencyEditor currencyEditor = new UltraCurrencyEditor(); currencyEditor.BorderStyle = Infragistics.Win.UIElementBorderStyle.None; // Need this to have dollar sign showing. //currencyEditor.FormatString = "C"; currencyEditor.Location = new System.Drawing.Point(3, 41); if (_isMoneyInCents) { currencyEditor.MaskInput = "-nnnnnnnnnnnnnnn.nn"; } else { currencyEditor.MaskInput = "-nnnnnnnnnnnnnnnnn"; } currencyEditor.MaxValue = decimal.MaxValue; currencyEditor.MinValue = decimal.MinValue; currencyEditor.Name = "currencyEditor"; currencyEditor.PromptChar = ' '; currencyEditor.Size = new System.Drawing.Size(100, 17); currencyEditor.TabIndex = 1; currencyEditor.TabStop = false; currencyEditor.Visible = false; currencyEditor.FormatProvider = Thread.CurrentThread.CurrentCulture; currencyEditor.FormatString = "N"; Controls.Add(currencyEditor); _editorControls.Add(key, currencyEditor);
+ Bind the grid to a datasource, for example, I have 2 properties like below. If we bind the column to AmtValue, the value is displayed correctly with grouping separator. However, this is an decimal, which is not nullable, it will cause us some trouble.
If we bind the column to AmtText, the line _amt.Value.ToString(Thread.CurrentThread.CurrentCulture); will not return the string with separator. Note: I cannot change the code in AmtText.
So my question is if we have anyway to intercept the way that ultra grid show the value in display mode? Can I inherit from UltraCurrencyEditor and make some changes to do it?
I think that I can use UltraControlContainerEditor to do this. But that solution seems too complex for this purpose.
Please advise
/// <summary> /// This is used for data binding /// </summary> public decimal AmtValue { get { if (_amt.IsNull) { return 0; } else { return _amt.Value; } } set { Amt = value; } } /// <summary> /// This is used for data binding /// </summary> public string AmtText { get { if (_amt.IsNull) { return string.Empty; } else { return _amt.Value.ToString(Thread.CurrentThread.CurrentCulture); } } set { if (value.Trim().Length == 0) { value = string.Empty; } Amt = NullConvert.ToNullableDecimal(value, string.Empty); } }
Is there any progress on this yet? I really need this done asap.
Hello Colin Moore,
Sorry for making you wait for response from us.
Yes, you can intercept the values assigned to and from editor and its owner by implementing IDataFilter interface.Details and sample codes can be seen in the following online help document.https://es.infragistics.com/help/winforms/wingrid-using-the-ieditordatafilter-interface-with-wingrid
I hope this will help.
Best Regards,
Noriko I.Technical Consulting EngineerInfragistics, Inc.
Hi Colin,
I'm glad to know that you solve the issue.If you have any other questions, do not hesitate to ask.
Nevermind, I found the issue.
I should use OwnerToEditor. It is working now
Thanks a lot for your help.
Hi Noriko,
I tried to implement IEditorDataFilder with below code:
public class CurrencyConverter: IEditorDataFilter { public object Convert(EditorDataFilterConvertArgs conversionArgs) { switch (conversionArgs.Direction) { case ConversionDirection.EditorToDisplay: { if (conversionArgs.Value != null) { if (!(conversionArgs.Value is string) || !string.IsNullOrEmpty(conversionArgs.Value as string)) { var decimalValue = 0m; try { decimalValue = System.Convert.ToDecimal(conversionArgs.Value); conversionArgs.Handled = true; return decimalValue.ToString("N", Thread.CurrentThread.CurrentCulture); } catch { } } } } break; default: break; } return conversionArgs.Value; } }
currencyEditor.DataFilter = new CurrencyConverter();
Debugging the code, it does go to Convert method, value return is also correct.However, the display text in the grid does not reflect that.
Do I miss anything?
Thanks