Changing "0.00" into "" - Removing Zero Values

3 posts, 1 answers
  1. SMCRadUser
    SMCRadUser avatar
    3 posts
    Member since:
    Sep 2009

    Posted 30 Apr 2012 Link to this post

    Good Morning Telerik Community,

    I am attempting to format certain cells in my RadGridView to remove the text from a cell if its value == 0.0 ... It works but for what ever reason it is Very slow and takes about two seconds to continue... Am I doing something wrong?

    Note: The extension method String.ToDecimal() attempts to convert the string to a decimal and returns a decimal?, null if it failed. I've replaced it with a standard Convert.ToDecimal() and it made no difference..

            private Boolean CellFormatting { get; set; }
      
            private void gridGLDetails_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
            {
      
                if (!CellFormatting && (e.Column.HeaderText == "Credit" || e.Column.HeaderText == "Debit") && e.CellElement.Text.ToDecimal() == 0.0M)
                {
                    CellFormatting = true;
                    e.CellElement.Text = "";
                    CellFormatting = false;
                }
      
    }
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 30 Apr 2012 Link to this post

    Hello, 

    Unless I've misunderstood your request, this should work for you. 

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.RowIndex > -1 && e.Column.Name == "Credit")
        {
            if (Convert.ToDecimal(e.CellElement.Value) == 0)
            {
                e.CellElement.Text = "";
            }
        }
    }

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 03 May 2012 Link to this post

    Hello,

    I have marked Richard's post as an answer. Please let us know whether this works for you.
     
    Kind regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top