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
405
Dislplay summary values as blank when total is coming as Zero in ultrawingrid
posted

Hi,

I am using ultrawingrid and I am calculating summaries by doing:

SummarySettings summary1 = gdOverView.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, columnname);

summary1.DisplayFormatDisplayFormat = "{0:0.00}";

Now if in my grid if all the cell values of particular column is coming as blank, then it showing summary value for that column is 0.00.

However, instead of showing 0.00, I want to show blank in summary cell for that column.

Thanks and Regards,
Rosy Malhotra

 

Parents
No Data
Reply
  • 990
    posted

    For this I would use a custom format provider. Declare a class like this:

        public class NumberFormatProvider : IFormatProvider, ICustomFormatter

        {

            #region IFormatProvider Members

     

            public object GetFormat(Type formatType)

            {

                if (formatType == typeof(ICustomFormatter))

                    return this;

                else

                    return null;

            }

     

            #endregion

     

            #region ICustomFormatter Members

     

            public string Format(string format, object arg, IFormatProvider formatProvider)

            {

                try

                {

                    if (arg.GetType() != typeof(float))

                        return "Unexpected data type";     // The number is not of the

                                                           // expected type so return a message.

                    else

                    {

                        float value = (float)arg;

                        if (value == 0f)

                            return string.Empty;           // If the number is 0 then return an

                                                           // empty string.

                        else

                            return value.ToString(format); // Return the number formatted

                                                           // according to format string.

                    }

                }

                catch (Exception ex)

                {

                    return ex.Message;

                }

            }

     

            #endregion

        }

    Then specify it in the SummarySettings:

        summary1.DisplayFormatProvider = new NumberFormatProvider();

    In this code I have assumed your using a 'float' data type. Change the type in the four places it's specified if necessary (or make the class more flexible by accepting more types).

    Andy.

     

     

Children
No Data