Tutorials > Tutorial 30 - Cell Bordering and Scroll Tips/Tracking |
In this tutorial you will utilize the Cell Border, Scroll Tips and Scroll Tracking features in True DBGrid. The Cell Border feature allows you to manipulate border options at run time, while the Scroll Tips and Scroll Tracking features allow you to track the location of your scroll bar and give the user an informational pop-up as the scroll bar moves.
Start a new project.
Based on the following illustration, place these three controls on the form: a True DBGrid control (TDBGrid1), an ADO Data control (Adodc1), a Common Dialog control (Cdlg).
Next, below the ADO data control, place a control array of check boxes named chkBorderType (0-3), where Top is 0, Left is 1, Bottom is 2 and Right is 3. Set the captions accordingly and set the Alignment property of the Left check box to 1 - Right Justify.
To the right of the check boxes, place two combo boxes. Name the first one cboBorderAppearance and set its Text property to "Border Appearance". Name the second one cboBorderSize and set its Text property to "Border Size".
Add a command button named cmdColor and set its Caption to "Border Color".
Finally, add a frame and place two check boxes (chkSTips and chkSTracking) inside it. Set the Caption properties as shown in the illustration.
Next we will connect Adodc1 to the TDBG8Demo database:
Display the custom property pages for Adodc1. Click the General tab and select the Use Connection String option. Click Build. Choose the Microsoft Jet 4.0 OLE DB Provider option. Click Next. Enter the datasource name by pressing the ellipsis buttonand locating the database (TDBGDEMO.MDB). Test the connection to make sure it works. Press OK to close the dialog window. Press the Apply button.
Choose the Recordsource tab. Set the Command Type to 2 – adCmdTable and the Table or Stored Procedure Name to Customers. Press the OK button to accept the selections and close the properties page.
Set the TDBGrid1 DataSource to Adodc1.
Set the List property of cboBorderAppearance to:
Example Title |
Copy Code
|
---|---|
Flat (Default) 3D Raised 3D Inset 3D Raised Bevel 3D Inset Bevel With the following code: Private Sub cboBorderAppearance_Click() Call setStyle End Sub |
Set the List property of cboBorderSize to 0 through 10 and add the following code:
Example Title |
Copy Code
|
---|---|
Private Sub cboBorderSize_Click() Call setStyle End Sub |
Set the RowHeight property of TDBGrid1 to 400.
Add the following code to cmdColor:
Example Title |
Copy Code
|
---|---|
Private Sub cmdColor_Click() cdlg.ShowColor Call setStyle End Sub |
Add the following code to chkSTracking:
Example Title |
Copy Code
|
---|---|
Private Sub chkSTracking_Click() TDBGrid1.ScrollTrack = chkSTracking.Value End Sub |
Add the following code to chkSTips:
Example Title |
Copy Code
|
---|---|
Private Sub chkSTips_Click() TDBGrid1.ScrollTips = chkSTips.Value End Sub |
Add the following code:
Example Title |
Copy Code
|
---|---|
Option Explicit Dim recset As ADODB.Recordset Dim border As TrueOleDBGrid80.StyleBorderTypeConstants Private Sub chkBorderType_Click(Index As Integer) Dim chk As CheckBox border = dbgBorderNone For Each chk In chkBorderType If chk.Value Then Select Case chk.Index Case 0: border = border Or dbgBorderTop Case 1: border = border Or dbgBorderLeft Case 2: border = border Or dbgBorderBottom Case 3: border = border Or dbgBorderRight End Select End If Next chk Call setStyle End Sub Private Sub Form_Load() 'Recordset for use with scroll tips/tracking. Set recset = Adodc1.Recordset.Clone cdlg.Color = vbGreen cboBorderAppearance.ListIndex = 3 cboBorderSize.ListIndex = 5 End Sub Private Sub setStyle() cmdColor.BackColor = cdlg.Color With TDBGrid1.Columns(TDBGrid1.Col).Style .BorderSize = IIf(cboBorderSize.ListIndex < 0, 0, cboBorderSize.ListIndex) .BorderColor = cdlg.Color .BorderType = border .BorderAppearance = IIf(cboBorderAppearance.ListIndex < 0, 0, cboBorderAppearance.ListIndex) End With End Sub Private Sub TDBGrid1_FetchScrollTips(ByVal SplitIndex As Integer, ByVal ColIndex As Integer, _ Bookmark As Variant, ByVal ScrollBar As TrueOleDBGrid80.ScrollBarsConstants, _ ScrollTip As String, ByVal TipStyle As TrueOleDBGrid80.StyleDisp) ' Gets called when scrolling occurs. ' Set the ScrollTip depending on which scroll bar was moved. Select Case ScrollBar Case dbgVertical: recset.Bookmark = Bookmark ScrollTip = "Record: " & CStr(recset.AbsolutePosition) & " of " & CStr(recset.RecordCount) & vbCrLf & _ "Company: " & recset("Company").Value & vbCrLf & _ "UserCode: " & recset("UserCode").Value Case dbgHorizontal: ScrollTip = TDBGrid1.Columns(ColIndex).Caption End Select TipStyle.ForeColor = vbBlue End Sub |
Run the program and observe the following:
You should have a form that looks like this:
Notice how you can now manipulate border options at run-time by using the check boxes and drop down menus.
Click on the Scroll Tips and Scroll Tracking check boxes. Notice how information is displayed as you scroll through the table using the scroll bar.
Congratulations, you have successfully completed all 30 tutorials!