Format specials Rows Grid

3 posts, 0 answers
  1. Andrés
    Andrés avatar
    6 posts
    Member since:
    Nov 2012

    Posted 13 Dec 2012 Link to this post

    Hello I need help to format the special rows of the grid. I send a picture to you to be an example of what we need.
    I also need to know how we can delete groups that meet a certain condition to not display (neither the group nor its component rows). For example I want not see groups with Total Group Sum less than 1000.
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 18 Dec 2012 Link to this post

    Hello Andrés,

    We will need some time in order to find a proper solution for your issue. I will write back when we have one. Thank you for your understanding and patience.

    If you have other questions, do not hesitate to write us.
     
    All the best,
    Jack
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 18 Dec 2012 Link to this post

    Hi Andrés,

    Directly to your questions:

    1. You can control the visual appearance of RadGridView cells by handling ViewCellFormatting and CellFormatting events. If you want to customize the cell alignment within the summary cell, the following code will be enough:

    void grid_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridSummaryCellElement sumCell = e.CellElement as GridSummaryCellElement;
        if (sumCell != null)
        {
            sumCell.TextAlignment = ContentAlignment.MiddleRight;
            sumCell.ForeColor = Color.Blue;
        }
    }

    However, if you want to align the text within the whole row, you should hide the summary cell. This is necessary because by default RadGridView creates a cell element specific for every column that contains summary items. Consider the following code snippet:

    void grid_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridSummaryCellElement sumCell = e.CellElement as GridSummaryCellElement;
        if (sumCell != null)
        {
            sumCell.Visibility = ElementVisibility.Collapsed;
        }
    }
             
    void grid_ViewRowFormatting(object sender, RowFormattingEventArgs e)
    {
        GridSummaryRowElement sumRow = e.RowElement as GridSummaryRowElement;
        if (sumRow != null)
        {
            sumRow.Text = sumRow.RowInfo.Cells["Value"].Value.ToString();
            sumRow.TextAlignment = ContentAlignment.MiddleLeft;
            sumRow.Padding = new Padding(42, 0, 0, 0);
            sumRow.ForeColor = Color.Red;
        }
    }

    2. You cannot delete groups that contain certain condition, however you can hide them. To do this you should use the IsVisible property of the group row and the Key property of its Group. Consider the sample below:

    grid.GroupDescriptors.Add(new GroupDescriptor("Value"));
     
    foreach (GridViewGroupRowInfo row in grid.ChildRows)
    {
        if ((int)((object[])row.Group.Key)[0] < 10)
        {
            row.IsVisible = false;
        }
    }

    In this case I am grouping by the Value column which contains integer values. All groups that correspond to a value lower than 10 will be hidden.

    I hope this helps.
     
    Regards,
    Jack
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top