ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Task-Based Help / Setting the Grid's Appearance / Setting the Background Color of a Row
In This Topic
    Setting the Background Color of a Row
    In This Topic

    To set the background color of a row, set the FetchRowStyles property to fire the FetchRowStyle event.

    Complete the following steps:

    1. Set the FetchRowStyles property to True.

      In the Designer

      Locate the FetchRowStyles property in the Properties window and set it to True.

      In Code

      Add the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.FetchRowStyles = True
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.FetchRowStyles = true;
      
    2. Specify the background color of the desired rows using the FetchRowStyle event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub C1TrueDBGrid1_FetchRowStyle(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs) Handles C1TrueDBGrid1.FetchRowStyle
          Dim S As String = C1TrueDBGrid1.Columns("Country").CellText(e.Row).ToString
          If S <> "Germany" Then
              e.CellStyle.BackColor = System.Drawing.Color.LemonChiffon
          End If
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void c1TrueDBGrid1_FetchRowStyle(object sender, C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs e) 
      { 
          string S = c1TrueDBGrid1.Columns("Country").CellText(e.Row).ToString; 
          if (S != "Germany") 
          { 
              e.CellStyle.BackColor = System.Drawing.Color.LemonChiffon; 
          } 
      }
      

    What You've Accomplished

    In this example, each row that does not contain the word "Germany" in the Country column has a background color of lemon chiffon: