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
120
Show "n.a." based on Cell-Value
posted

How can I show a special text if value is 0 in a cell, which is formated as show in the following code?

UltraGridColumn

ugc = UltraGrid.DisplayLayout.Bands[0].Columns[

 

"Anteil"];

ugc.MaskDataMode = MaskMode.IncludeLiterals;

 

 

ugc.MaskDisplayMode =

 

MaskMode.IncludeLiterals;

ugc.MinValue = 0;

ugc.MaxValue = 100;

 

 

 

ugc.MaskInput =

 

 

"nnn.nn\\%";

ugc.PromptChar = '_';

ugc.CellDisplayStyle =

 

CellDisplayStyle.FormattedText;

 

Parents
No Data
Reply
  • 69832
    Verified Answer
    Offline posted

    You can hack this out using the IEditorDataFilter interface and the NullText property:

    column.NullText = "n/a";
    column.MaskInput = "nnn.nn\\%";
    column.Editor.DataFilter = new ZeroToNullDataFilter();

    private class ZeroToNullDataFilter : IEditorDataFilter
    {
        object IEditorDataFilter.Convert(EditorDataFilterConvertArgs conversionArgs)
        {
            decimal? decimalValue =
                conversionArgs.Value is decimal ?
                (decimal)conversionArgs.Value :
                (decimal?)null;

            switch ( conversionArgs.Direction )
            {
                case ConversionDirection.OwnerToEditor:
                {
                    if ( decimalValue.HasValue && decimalValue.Value == 0m )
                    {
                        conversionArgs.Handled = true;
                        return System.DBNull.Value;
                    }
                }
                break;

                case ConversionDirection.EditorToOwner:
                {
                    if ( conversionArgs.Value == null )
                    {
                        conversionArgs.Handled = true;
                        return 0m;
                    }
                }
                break;
            }

            return conversionArgs.Value;
        }
    }

    The data filter tricks the column into thinking that zero is null, and the NullText property tells it what to display when the value is null.

Children