In this tutorial, you will learn how to change the grid's display to highlight rows by creating row styles depending upon a value in the grid. True DBGrid uses the FetchRowStyle event to create style characteristics and apply them to rows dynamically.
Complete the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim bflag As Integer |
To write code in C#
C# |
Copy Code
|
---|---|
int bflag; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Prospective Customers. Me.C1TrueDBGrid1.FetchRowStyles = True bFlag = 1 Me.C1TrueDBGrid1.Refresh() |
To write code in C#
C# |
Copy Code
|
---|---|
// Prospective Customers. this.c1TrueDBGrid1.FetchRowStyles = true; bFlag = 1; this.c1TrueDBGrid1.Refresh(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Distributors. Me.C1TrueDBGrid1.FetchRowStyles = True bFlag = 2 Me.C1TrueDBGrid1.Refresh() |
To write code in C#
C# |
Copy Code
|
---|---|
// Distributors. this.c1TrueDBGrid1.FetchRowStyles = true; bFlag = 2; this.c1TrueDBGrid1.Refresh(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Reset the grid. Me.C1TrueDBGrid1.FetchRowStyles = False Me.C1TrueDBGrid1.Refresh() |
To write code in C#
C# |
Copy Code
|
---|---|
// Reset the grid. this.c1TrueDBGrid1.FetchRowStyles = false; this.c1TrueDBGrid1.Refresh(); |
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 If bFlag = 1 And Me.C1TrueDBGrid1 (e.Row,"CustType") = 1 Then Dim fntFont As New Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold) e.CellStyle.Font = fntFont e.CellStyle.ForeColor = System.Drawing.Color.Blue End If If bFlag = 2 And Me.C1TrueDBGrid1 (e.Row, "CustType") = 4 Then e.CellStyle.ForeColor = System.Drawing.Color.White e.CellStyle.BackColor = System.Drawing.Color.Red End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void C1TrueDBGrid1_FetchRowStyle(object sender, C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs e) { if (bFlag == 1 && (int)this.c1TrueDBGrid1 [e.Row, "CustType"] == 1 ) { Font fntFont = new Font(e.CellStyle.Font.Name, e.CellStyle.Font.Size, FontStyle.Bold); e.CellStyle.Font = fntFont; e.CellStyle.ForeColor = System.Drawing.Color.Blue; } if (bFlag == 2 && this.c1TrueDBGrid1 [e.Row, "CustType"] == 4 ) { e.CellStyle.ForeColor = System.Drawing.Color.White; e.CellStyle.BackColor = System.Drawing.Color.Red; } } |
You've successfully completed using styles to highlight related data; this concludes tutorial 11.