Highlight Repeated Records in C1Report

C1Report is the data-based banded report in which the Detail Section is rendered for each record in the data-source. Since, the rendering of the Detail Section takes place exclusively for each record, it is difficult to have the following implementations:

  1. Get the value of a cell from the next row
  2. Modify the existing Format of rendered Detail Section

Now the question is, why and when would we require the above two scenarios. This blog helps you in finding the answer to the same. Lately, one of our customers wanted to check if a column had duplicate records and if yes, then highlight them. Since, we cannot get the value of the cell from next row, we cannot determine if it's a duplicate value. Alternate way is to compare the present value with the previously fetched records and check for multiple existence. However, we can only set the back-color for the to-be rendered field and cannot format the previously rendered Detail Sections or its fields. So neither of the above options meet the requirement. The only trick to achieve the required behavior is to add the VBscript code in the OnFormat property of the Detail Section. However, this time it is implemented in code and not through C1ReportDesigner. A simple approach is to get all the values in a List and then loop through each item of the List, checking if the same appears more than once. If the value exists multiple times, then all the occurrences of that value will be highlighted in the resultant report. Use the given code snippet to implement the requirement :

For i = 0 To Table1.Rows.Count - 1  

For Each item As String In list  
  If Not list2.Contains(item) Then  
    If list.LastIndexOf(item) <> list.IndexOf(item) Then  
    End If  
  End If  
For Each str As String In list2  
  If flag = 0 Then  
    script\_n = script\_n + "Values= """ + str + """"  
    ElseIf flag = 1 Then  
      script\_n = script\_n + " or Values= """ + str + """"  
    End If  
  flag = 1  

C1Report.Load("New_RepeatValues.xml", "Table1 Report")  
Dim script As String = ""  
script = "If " + script_n + " Then" + vbCrLf + "ValuesCtl.BackColor=rgb(155,155,250)" + vbCrLf + "else" + vbCrLf + " ValuesCtl.BackColor=rgb(255,255,255)" + vbCrLf + "endif"  
C1Report.Sections("Detail").OnFormat = script  
C1PrintPreviewControl1.Document = C1Report

Following output is generated using the above code: Refer to the attached samples for complete implementation. Download Sample - VB Download Sample - CS


GrapeCity Developer Tools
comments powered by Disqus