| List for WinForms Task-Based Help > Setting the Foreground Color of a Row |
To set the foreground color of a row, use the FetchRowStyles property and the FetchRowStyle event.
Set the FetchRowStyles property to True:
Locate the FetchRowStyles property in the Properties window and set it to True:
Alternatively you can add code to set the FetchRowStyles property. Add the following code to the project, for example to the Button1_Click event:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Me.C1List1.FetchRowStyles = True |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
this.c1List1.FetchRowStyles = true; |
|
Add the following FetchRowStyle event to identify the customer type by color.
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 C1List1.Columns("CustType").CellText(e.Row) = "1" Then
e.CellStyle.ForeColor = System.Drawing.Color.DarkGoldenrod
ElseIf C1List1.Columns("CustType").CellText(e.Row) = "2" Then
e.CellStyle.ForeColor = System.Drawing.Color.Crimson
ElseIf C1List1.Columns("CustType").CellText(e.Row) = "3" Then
e.CellStyle.ForeColor = System.Drawing.Color.DarkGreen
ElseIf C1List1.Columns("CustType").CellText(e.Row) = "4" Then
e.CellStyle.ForeColor = System.Drawing.Color.DarkCyan
ElseIf C1List1.Columns("CustType").CellText(e.Row) = "5" Then
e.CellStyle.ForeColor = System.Drawing.Color.DarkOrchid
End If
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void C1List1_FetchRowStyle( object sender, C1.Win.C1List.FetchRowStyleEventArgs e)
{
if (c1List1.Columns["CustType"].CellText(e.Row) == "1")
{
e.CellStyle.ForeColor = System.Drawing.Color.DarkGoldenrod;
}
else if (c1List1.Columns["CustType"].CellText(e.Row) == "2")
{
e.CellStyle.ForeColor = System.Drawing.Color.Crimson;
}
else if (c1List1.Columns["CustType"].CellText(e.Row) == "3")
{
e.CellStyle.ForeColor = System.Drawing.Color.DarkGreen;
}
else if (c1List1.Columns["CustType"].CellText(e.Row) == "4")
{
e.CellStyle.ForeColor = System.Drawing.Color.DarkCyan;
}
else if (c1List1.Columns["CustType"].CellText(e.Row) == "5")
{
e.CellStyle.ForeColor = System.Drawing.Color.DarkOrchid;
}
}
|
|
When the Foreground Color button is clicked, the customer type is identified by color.
