To format rows based on specific criteria, use the FetchRowStyles property and the FetchRowStyle event. In this example, rows that do not have values in the Birth or Death columns will be highlighted green and all other rows will be locked and formatted in Steel Blue, Tahoma font.
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; |
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 End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TrueDBGrid1_FetchRowStyle(object sender, C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs e) { } |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Declare variables to get the values in the columns. Dim bday As String = Me.C1TrueDBGrid1.Columns("Birth").CellText(e.Row).ToString Dim ddate As String = Me.C1TrueDBGrid1.Columns("Death").CellText(e.Row).ToString |
To write code in C#
C# |
Copy Code
|
---|---|
// Declare variables to get the values in the columns. string bday = this.c1TrueDBGrid1.Columns["Birth"].CellText(e.Row).ToString; string ddate = this.c1TrueDBGrid1.Columns["Death"].CellText(e.Row).ToString; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' If the Birth or Death column does not contain an empty cell, disable editing and change the font. If (bday <> "" AndAlso ddate <> "") And (bday <> "" OrElse ddate <> "") Then e.CellStyle.Locked = True e.CellStyle.Font = New Font("Tahoma", 9) e.CellStyle.ForeColor = Color.SteelBlue End If |
To write code in C#
C# |
Copy Code
|
---|---|
// If the Birth or Death column does not contain an empty cell, disable editing and change the font. if ((bday != "" && ddate != "") And (bday != "" || ddate != "")) { e.CellStyle.Locked = true; e.CellStyle.Font = new Font("Tahoma", 9); e.CellStyle.ForeColor = Color.SteelBlue; } |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' If the Birth or Death column contains an empty cell, highlight the row. If bday = "" Or ddate = "" Then e.CellStyle.BackColor = Color.PaleGreen End If |
To write code in C#
C# |
Copy Code
|
---|---|
// If the Birth or Death column contains an empty cell, highlight the row. if (bday == "" || ddate == "" { e.CellStyle.BackColor = Color.PaleGreen; } |
Rows with blank values in the Birth or Death column are highlighted and all other rows are not editable and in a different font. Adding a value to a blank cell will change the formatting of the cell.