This is a migrated thread and some comments may be shown as answers.

Total row formatting

3 Answers 307 Views
GridView
This is a migrated thread and some comments may be shown as answers.
FilipN
Top achievements
Rank 1
FilipN asked on 03 Aug 2009, 09:38 AM
Hello,
I am using GridViewSummaryRowItem and i found it very useful so far. However I have problem with adding custom format (color, border) to the total row. In examples there is code snippet that uses  cell formatting event to do so:

  if (e.CellElement is GridSummaryCellElement) 
            { 
 //Set formatting... 
            } 


But my GridView doesn't fire either cellfromatting or rowformatting event for the total row, so I have no way how for example set custom background color. Here's my code to setup the total row:

     
      GridViewSummaryRowItem sum = new GridViewSummaryRowItem(); 
            sum.Add(new GridViewSummaryItem("CeleJmeno""Celkem", GridAggregateFunction.None)); 
            sum.Add(new GridViewSummaryItem("Preplatek""{0:C}", GridAggregateFunction.Sum)); 
            sum.Add(new GridViewSummaryItem("Zustatek""{0:C}", GridAggregateFunction.Sum)); 
 
            this.grdHromadnaVyplatnice.MasterGridViewTemplate.SummaryRowsBottom.Add(sum); 

3 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 03 Aug 2009, 10:02 AM
Hi FilipN,

CellFormatting event fires only for data cells. The summary row doesn't have a representation in the data source and you should handle ViewCellFormatting event instead. Here is a sample:

void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
    GridSummaryCellElement cell = e.CellElement as GridSummaryCellElement; 
    if (cell != null
    { 
        object[] values = cell.Values; 
        if ((int)values[0] > 5) 
        { 
            e.CellElement.ForeColor = Color.Red; 
        } 
        else 
        { 
            e.CellElement.ForeColor = Color.Black; 
        } 
    } 

Please write us back if you have any questions.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Doug Hamilton
Top achievements
Rank 1
answered on 03 Nov 2009, 04:25 PM
I am having trouble implementing this using VB.Net.  I can't get the correct syntax for checking to see if the grid is positioned on the summary row to do the formatting.  Any help would be appreciated.  Here is the code I am currently trying to use:

    Private Sub uiDelinquent_Importgrd_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles uiDelinquent_Importgrd.ViewCellFormatting  
 
        Dim cell As GridSummaryCellElement = New GridSummaryCellElement()  
 
        If (e.CellElement Is cell) Then  
            e.CellElement.ForeColor = Color.Blue  
            e.CellElement.BackColor = Color.CadetBlue  
        End If  
 
    End Sub  
 


Doug
0
Doug Hamilton
Top achievements
Rank 1
answered on 03 Nov 2009, 04:48 PM
After further thought.... I decided to actually look at one of the examples for the Gridview that comes with the install of the telerik control and discovered my answer!

        Private Sub radGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)  
            If TypeOf e.CellElement Is GridSummaryCellElement Then  
                e.CellElement.DrawBorder = True 
                e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders  
                e.CellElement.BorderLeftWidth = 0 
                e.CellElement.BorderRightWidth = 0 
                e.CellElement.BorderBottomWidth = 0 
                e.CellElement.BorderTopWidth = 1 
                e.CellElement.BorderTopColor = Color.Black  
                e.CellElement.TextAlignment = ContentAlignment.MiddleLeft  
            End If  
        End Sub  
 

Which has put me on the path to enlightenment!  dooooh!!!

Doug
Tags
GridView
Asked by
FilipN
Top achievements
Rank 1
Answers by
Jack
Telerik team
Doug Hamilton
Top achievements
Rank 1
Share this question
or