Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
155
Intercept how value is displayed in UltraGrid
posted

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);
            }
        }

Parents Reply Children
No Data