How do I align a SummaryRowsBottom Cell to be right justified?

9 posts, 0 answers
  1. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 01 Dec 2010 Link to this post

    Hi

    I have a radgrid which has a summary rows bottom field.

    It is displaying at runtime as centered.

    how can i right justify it?

    Kind Regards

    David
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 01 Dec 2010 Link to this post

    Hello David,

    you need to use teh ViewCellFormatting event. See code below.

    Private Sub RadGridView1_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
        If TypeOf e.CellElement Is Telerik.WinControls.UI.GridSummaryCellElement Then
            e.CellElement.TextAlignment = ContentAlignment.MiddleRight
        End If
    End Sub

    hope that helps, but let me know if you need anyhting else
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 01 Dec 2010 Link to this post

    Hello,

    How did this go for you? If it is all fine now, please mark as answer so others can find the solution too. If you need more help, just let me know.
    thanks
    Richard
  5. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 02 Dec 2010 Link to this post

    Hi Richard

    Thank you very much for the reply.

    Unfortunately this did not work for me. The column summary is still centered.

    I am using the latest internal build.

    Any other ideas?

    Kind Regards

    David
  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 02 Dec 2010 Link to this post

    Hello,

    Richard suggestion is the way to go on this one,
    Please take a look at the following example:
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    public partial class Form1 : Form
    {
        private RadGridView radGridView1;
     
        public Form1()
        {
            InitializeComponent();
            this.Controls.Add(radGridView1 = new RadGridView());
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.ViewCellFormatting += new CellFormattingEventHandler(radGridView1_ViewCellFormatting);
            radGridView1.Dock = DockStyle.Fill;
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
     
            var summaryItem = new GridViewSummaryItem("ValueToEnter", "Values: {0}", GridAggregateFunction.Sum);
            var summaryRow = new GridViewSummaryRowItem(new[] { summaryItem });
            radGridView1.SummaryRowsBottom.Add(summaryRow);
             
            radGridView1.DataSource = new TestsCollection();
        }
     
        void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement is GridSummaryCellElement)
            {
                e.CellElement.TextAlignment = ContentAlignment.BottomRight;
            }
        }
    }
     
    public class Test
    {
        public int ValueToEnter
        {
            get;
            set;
        }
     
        public int CalculatedValue
        {
            get;
            set;
        }
    }
     
    public class TestsCollection : BindingList<Test>
    {
        public TestsCollection()
        {
            for (int i = 0; i < 3; i++)
            {
                this.Add(new Test
                    {
                        ValueToEnter = i,
                        CalculatedValue = 0
                    });
            }
        }
    }

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP
  7. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 02 Dec 2010 Link to this post

    Hi

    This is great! My columns are now right justified...

    BUT. They have lost their FormatString formatting of "{0:C}".

    NB: I am creating the SumarryRowBottom @ design time through the property editor.

    Any ideas?

    Kind Regards

    David
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 02 Dec 2010 Link to this post

    Hi David,

    Have a check to see if the format is still there in the designer editor. I added a summary row to an existing grid, and added the text align property and it's showing up fine. Failing that, I'd remove and re-add the summary row again.

    This is how it looks in my designer file
    'RadGridViewDynamicSummary1
    '
    GridViewSummaryItem1.Aggregate = Telerik.WinControls.UI.GridAggregateFunction.Sum
    GridViewSummaryItem1.FormatString = "{0:C}"
    GridViewSummaryItem1.Name = "Income"
    Me.RadGridViewDynamicSummary1.MasterTemplate.SummaryRowsBottom.Add(New Telerik.WinControls.UI.GridViewSummaryRowItem(New Telerik.WinControls.UI.GridViewSummaryItem() {GridViewSummaryItem1}))
    Me.RadGridViewDynamicSummary1.Name = "RadGridView1"
    Me.RadGridViewDynamicSummary1.Size = New System.Drawing.Size(456, 311)
    Me.RadGridViewDynamicSummary1.TabIndex = 0
    Me.RadGridViewDynamicSummary1.Text = "RadGridView1"

    and attached is a screenshot
    Hope this helps
    Richard
  9. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 02 Dec 2010 Link to this post

    Hi Richard

    Thanks for the quick response.

    However, I posted rather prematurely. It seems that the formatting on the SummaryRowBottom is OK.

    It is the FormatString on the column itself that is not working.

    i.e. in your screen shot the Income column would need a format string of "{0:C}" to show the pound sign and 2 decimal places.

    Kind Regards

    David
  10. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 02 Dec 2010 Link to this post

    Hi David,

    you just need to add this somewhere after creating the columns:
    Me.RadGridView1.Columns("Income").FormatString = "{0:C}"

    for example, if you are creating them manually, directly after creating the column, or if you are auto creating the columns, in the DataBindingComplete event
    Private Sub RadGridViewDynamicSummary1_DataBindingComplete(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewBindingCompleteEventArgs) Handles RadGridViewDynamicSummary1.DataBindingComplete
        Me.RadGridViewDynamicSummary1.Columns("Income").FormatString = "{0:C}"
    End Sub

    hope that helps, but let me know if you have any more problems
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready