Formatting text in Group header with aggregate value;

7 posts, 0 answers
  1. Shaun
    Shaun avatar
    37 posts
    Member since:
    Sep 2012

    Posted 16 Apr 2014 Link to this post

    Hi,

    I have a grid with 3 aggregate footers, when the  user groups on a particular column I’m adding
    the aggregate  values to the group
    header, which works fine.

    But I cannot get the text to align , I have tried to pad the
    text with spaced with no success, here an image…


    What I’m hoping to do is basically align / give the illusion
    of  4 columns in the header,  one for the column title the other 3 for each  aggregate value.

    Here's some code:

    private void gviTicketSummary_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
    {
    int i = 0;

    if (e.SummaryItem == null)
    return;

    if (e.SummaryItem.Name == "Site")
    {
    int count = e.Group.ItemCount;
    decimal PlannedQty = 0;
    decimal ActualQty = 0;

    foreach (GridViewRowInfo row in e.Group)
    {
    PlannedQty += Convert.ToDecimal(row.Cells["PlannedQty"].Value);
    ActualQty += Convert.ToDecimal(row.Cells["ActualQty"].Value);
    }

    string sPlanned = PlannedQty.ToString("#,##0");
    string sPlannedNew = PlannedQty.ToString("#,##0");

    if (sPlanned.Length < 20)
    sPlannedNew = sPlanned.PadRight(20, ' ');

    string sActual = ActualQty.ToString("#,##0");
    string sActualNew = ActualQty.ToString("#,##0");

    if (sActual.Length < 20)
    sActualNew = sActual.PadRight(20, ' ');

    string site = e.Value.ToString().Trim();

    string siteNew;
    if (site.Length < 20)
    {
    siteNew = site.PadRight(20, ' ');
    }
    else
    siteNew = site;


    string Header = string.Concat(siteNew, " Planned Tonnes :", sPlannedNew, "Actual Tonnes : ", sActualNew);

    // e.FormatString = String.Format("{0}Planned Tonnes : {1} Actual Tonnes : {2}", siteNew, sPlannedNew, sActualNew);

    e.FormatString = Header;


    }



    Hope this makes sense

     

    Thanks

     

    Shaun

  2. Dimitar
    Admin
    Dimitar avatar
    1410 posts

    Posted 18 Apr 2014 Link to this post

    Hello Shaun,

    Thank you for contacting us.

    In this case in order this to work you should use monospaced font. This way the the strings will have equal size and they will be aligned properly. The font can be changed in the ViewRowFormatting event:
    Font f = new Font("Consolas", 9, FontStyle.Regular);
    void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
    {
        if (e.RowElement is GridGroupHeaderRowElement)
        {
            e.RowElement.Font = f;
        }
        else
        {
            e.RowElement.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }

    More information about the formatting event is available in the following article: Formatting Rows.

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Shaun
    Shaun avatar
    37 posts
    Member since:
    Sep 2012

    Posted 21 Apr 2014 in reply to Dimitar Link to this post

    Hi Dimitar,

    Excellent, just what I wanted.
    Not 100% sure but I don't think I got the normal email with your post.

    Just need to work out how to export just the closed group headers to Excel.


    Thanks

    Shaun.
  5. Dimitar
    Admin
    Dimitar avatar
    1410 posts

    Posted 22 Apr 2014 Link to this post

    Hello Shaun,

    Thank you for writing back.

    In this case to export only the group header rows you can hide all other rows and set the exporter HiddenRowOption to DoNotExport. For example you can export the grid upon a button click like this:
    private void radButton1_Click(object sender, EventArgs e)
    {
        ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
        exporter.HiddenRowOption = HiddenOption.DoNotExport;
     
        string fileName = "C:\\ExportedData123.xls";
     
        radGridView1.ShowColumnHeaders = false;
        foreach (var item in radGridView1.Rows)
        {
            item.IsVisible = false;  
        }
     
        exporter.RunExport(fileName);
     
        radGridView1.ShowColumnHeaders = true;
        foreach (var item in radGridView1.Rows)
        {
            item.IsVisible = true;
        }
    }

    As to the notification mail at hand, currently we do not have any other reports for this and if you continue to not receive such mails please get back to us, and we will further investigate this case.

    Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 29 May 2015 Link to this post

    Hi, everyone.

    I have a problem when formatting text in group row.

    In my RadGridView I have an invisible column "GroupByList" which contains an expression:

        'CodList: ' + CodList + '   Date: ' + DeadLineDate + '  Description: ' + Descr.

    where the names are the fieldnames from respective columns of the RadGridView. Accordingly, in the event "GroupSummaryEvaluate" I have written the line:  "e.FormatString("{0},  {1}", e.Value, e.ItemCount);" to show the text in the group row.

    Presently my group row looks like:

         "CodList: A001123     Date:  29/05/2015  00:00:00    ListDescription: Clothes and Accessories". 

    However, I want my group row to look like:

         "CodList: A001123     Date:  29/05/2015      ListDescription: Clothes and Accessories".

     i.e. I want the date to contain no time.

     

    I try to format the date expression with the standard radgridview built-in expression formatting function "GETDATE()", but it didn't work. I also tried to set the value of the "FormatString" property of the "GroupByList" column to "{0:d}". This didn't work either.

    Could you, please, suggest any solutions for the issue?

    Thanks a lot in advance.

     

    Best Regards,

    Jeen.

  7. Dimitar
    Admin
    Dimitar avatar
    1410 posts

    Posted 01 Jun 2015 Link to this post

    Hello Jeen,

    Thank you for writing.

    After it is calculated the value is string and you cannot use the format string to format it like a DateTime object. What you can do is manually change the string and remove the time. For example:
    void radGridView1_GroupSummaryEvaluate(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
    {
        string date = "Date: ";
        int startIndex = e.Value.ToString().IndexOf(date) + date.Length + 10;
        string newValue = e.Value.ToString().Remove(startIndex, 9);
        e.FormatString = string.Format("{0}", newValue);
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 02 Jun 2015 in reply to Dimitar Link to this post

    Hi, Dimitar.

    Your solution suits me quite well)

    Thank you very much for your help!

     

    Best regards,

    Jeen

Back to Top
UI for WinForms is Visual Studio 2017 Ready