ComponentOne List for WinForms
In This Topic
    Tutorial 10 - Using Row Styles to Highlight Related Data
    In This Topic

    In this tutorial, you will learn how to change the list's display to highlight rows by creating row styles depending upon a value in the list. C1List uses the FetchRowStyle event to create style characteristics and apply them to rows dynamically.

    1. Follow steps 1 through 6 of Tutorial 8 - Displaying Translated Data, setting SELECT * FROM CUSTOMERS as the SQL statement, to create a project with a C1List control bound to a Data Set.
    2. Add thee buttons to the form. Change the caption of Button1 to "Prospective Customers", Button2 to "Distributors", and Button3 to "Reset the List" so that the form appears as follows.
    3. Add the following declarations to the General section of Form1:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Dim bFlag1, bFlag2 As Boolean
      

      To write code in C#

      C#
      Copy Code
      bool bFlag1, bFlag2;
      
    4. Enter the following code in the Button1_Click event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1List1.FetchRowStyles = True
      bFlag1 = True
      Me.C1List1.Refresh()
      

      To write code in C#

      C#
      Copy Code
      this.c1List1.FetchRowStyles = true;
      bFlag1 = true;
      this.c1List1.Refresh();
      
    5. Enter the following code in the Button2_Click event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1List1.FetchRowStyles = True
      bFlag2 = True
      Me.C1List1.Refresh()
      

      To write code in C#

      C#
      Copy Code
      this.c1List1.FetchRowStyles = true;
      bFlag2 = true;
      this.c1List1.Refresh();
      
    6. Enter the following code in the Button3_Click event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1List1.FetchRowStyles = True
      bFlag1 = False
      bFlag2 = False
      Me.C1List1.Refresh()
      

      To write code in C#

      C#
      Copy Code
      this.c1List1.FetchRowStyles = true;
      bFlag1 = false;
      bFlag2 = false;
      this.c1List1.Refresh();
      
    7. Enter the following code in the FetchRowStyle event. This code interacts with the setting of the FetchRowStyles property in the click event. When the FetchRowStyles is set to True, the list fires FetchRowStyle event when it needs to repaint the cells. Thus the row style is applied according to the value of the bflag flag integer:

      To write code in Visual Basic

      Visual Basic
      Copy Code
          
      Private Sub C1List1_FetchRowStyle(ByVal sender As Object, ByVal e As C1.Win.C1List.FetchRowStyleEventArgs) Handles C1List1.FetchRowStyle    
          If (bFlag1 And Me.C1List1.Columns("CustType").CellValue(e.Row) = 1) Then    
       Dim fntFont As New Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold)    
       e.CellStyle.Font = fntFont    
       e.CellStyle.ForeColor = Color.Blue    
          End If    
          If (bFlag2 And Me.C1List1.Columns("CustType").CellValue(e.Row) = 4) Then   
       e.CellStyle.ForeColor = Color.White    
       e.CellStyle.BackColor = Color.Red    
          End If
      End Sub
      
      

      To write code in C#

      C#
      Copy Code
          
      private void C1List1_FetchRowStyle( object sender, C1.Win.C1List.FetchRowStyleEventArgs e)    
      {    
          if (bFlag1 && this.c1List1.Columns["CustType"].CellValue(e.Row) == 1)    
          {    
       Font fntFont = new Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold);    
       e.CellStyle.Font = fntFont;    
       e.CellStyle.ForeColor = Color.Blue;    
          }    
          if (bFlag2 && this.c1List1.Columns["CustType"].CellValue(e.Row) == 4)   
          {    
       e.CellStyle.ForeColor = Color.White;    
       e.CellStyle.BackColor = Color.Red;  
          }    
      }
      
      

    Run the program and observe the following:

    This concludes the tutorial.