ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Setting the Background Color of a Row

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

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:

·      Visual Basic

Me.C1TrueDBGrid1.FetchRowStyles = True

·      C#

this.c1TrueDBGrid1.FetchRowStyles = true;

·      Delphi

Self.C1TrueDBGrid1.FetchRowStyles :=True;

2.   Specify the background color of the desired rows using the FetchRowStyle event:

·      Visual Basic

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

·      C#

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;

    }

}

·      Delphi

Procedure TForm1.C1TrueDBGrid1_FetchRowStyle(sender: object; e: C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs);

var

  S: string;

begin

  S := C1TrueDBGrid1.Columns['Country'].CellText(e.Row).ToString;

  if (S <> 'Germany') then

    e.CellStyle.BackColor := System.Drawing.Color.LemonChiffon;

end;

This topic illustrates the following:

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


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.