Tutorials > Tutorial 10 - Using Styles to Highlight Related Data |
In this tutorial, you will learn how to change the list's display to highlight rows by defining new styles at run time. True DBList uses Style objects to apply font and color characteristics to rows, columns, and individual cells.
Start with the project used in Tutorial 9.
Add a control array of three command buttons to the form. Change the captions of Command1(0) to Prospective Customers, Command1(1) to Distributors, and Command1(2) to Reset the List so that the form appears as follows.
Add the following declarations to the General section of Form1:
Example Title |
Copy Code
|
---|---|
Dim ButtonFlag As Integer Dim Prospective As New TrueDBList80.Style Dim Distributors As New TrueDBList80.Style |
Enter the following code in the Click (Visual Basic) event of Command1:
Example Title |
Copy Code
|
---|---|
Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 ButtonFlag = 0 TDBList1.FetchRowStyle = True Case 1 ButtonFlag = 1 TDBList1.FetchRowStyle = True Case 2 TDBList1.FetchRowStyle = False End Select TDBList1.Refresh End Sub |
Enter the following code in the Form_Load (Visual Basic) event:
Example Title |
Copy Code
|
---|---|
Private Sub Form_Load() Set Prospective = TDBList1.Styles.Add("Prospective") Prospective.Font.Italic = True Prospective.Font.Bold = True Prospective.ForeColor = vbBlue Set Distributors = TDBList1.Styles.Add("Distributors") Distributors.BackColor = vbRed Distributors.ForeColor = vbWhite End Sub |
Enter the following code in the FetchRowStyle event of TDBList1:
Example Title |
Copy Code
|
---|---|
RSClone.Bookmark = Bookmark If ButtonFlag = 0 And RSClone("CustType").Value = 1 Then RowStyle = Prospective End If If ButtonFlag = 1 And RSClone("CustType").Value = 4 Then RowStyle = Distributors End If |
Run the program and observe the following:
TDBList1 displays data as in Tutorial 9.
Click the Prospective Customers button.The list should appear as follows.
Click the Distributors button. The list should now appear as follows:
Finally, click the Reset the list button. The list should now appear as follows.
To end the program, press the End button on the Visual Basic toolbar. You have successfully completed Tutorial 10.