FlexGrid Footer Format Specifier?

Posted by: david.hoffman on 14 January 2020, 6:12 pm EST

    • Post Options:
    • Link

    Posted 14 January 2020, 6:12 pm EST

    I’m able to get a footer for a column that displays the total sum of all values for that column…

    flexGrid.Footers.Descriptions.Add(new FooterDescription());

    flexGrid.Footers.Descriptions[0].Aggregates.Add(new AggregateDefinition() { Column = 4, Aggregate = AggregateEnum.Sum });

    But I’d like to format the number with commas. For example, I’d like to format the number “1234.56” as “1,234.56”.

    Does anyone know how to do this?

    For a normal column I can just do this…

    flexGrid.Cols[InvoiceReportColumns.Total].Format = “#,##0.00”;

    But how can I do this for an aggregate in the footer?

  • Posted 15 January 2020, 2:29 am EST

    Hi David,

    You can use the OwnerDrawCell event to achieve your desired result by using the code snippet given below :

    private void C1FlexGrid1_OwnerDrawCell(object sender, OwnerDrawCellEventArgs e)
    {
     if (e.Col == c1FlexGrid1.Cols["ColumnName"].Index && e.Row == c1FlexGrid1.Rows.Count - 1)
        {
         double d = Convert.ToDouble(e.Text);
         e.Text = String.Format("{0:#,##0.00}",d);   
        }
    }
    

    We have attached a demo sample for help, please have a look.

    Regards,

    Prabhat

    FooterFormatDemo.zip

  • Posted 15 January 2020, 8:59 am EST

    Thank you! This worked like a champ. Exactly what I needed.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels