v7.0 版本没错!v8.0.20024.294 控制 DataView 和 ScrollBars 竟然有 Bug,无法控制!终于:
v8.0.20031.300 又改好了!
效果:
双击改变 DataView => InvertedView
注意改变 Form 大小时,根据 VScrollWidth 控制 ViewColumnWidth!
'Objects: Form1、TDBGrid1
Option Explicit
Private Sub InvertView(TDBGridX As TrueOleDBGrid80.TDBGrid)
If TDBGridX.DataView <> dbgInvertedView Then
   TDBGridX.DataView = dbgNormalView
   TDBGridX.DataView = dbgInvertedView
   Dim adoRecordset As ADODB.Recordset
   Set adoRecordset = TDBGrid1.DataSource
   adoRecordset.Move 0
   AdjustViewColumnAndCaptionWidth TDBGridX
Else
   TDBGridX.DataView = dbgGroupView
   TDBGridX.ScrollBars = dbgAutomatic
End If
End Sub
Private Sub Form_Load()
TDBGrid1.AboutBox
Dim adoConnection As New ADODB.Connection
Dim adoRecordset As New ADODB.Recordset
'adoConnection.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=TRIATON\PSQL2KE"
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\NWind2K.mdb;Persist Security Info=False"
adoRecordset.Open "select * from 产品", adoConnection, adOpenKeyset
Set TDBGrid1.DataSource = adoRecordset
TDBGrid1.Splits.Item(0).AllowColMove = True
TDBGrid1.DataView = dbgGroupView
TDBGrid1.Left = 0
TDBGrid1.Top = 0
End Sub
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
   TDBGrid1.Width = Me.Width - 120
   TDBGrid1.Height = Me.Height - 400
   If TDBGrid1.DataView = dbgInvertedView Then
      AdjustViewColumnAndCaptionWidth TDBGrid1
   End If
End If
End Sub
Private Sub TDBGrid1_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
AdjustViewColumnAndCaptionWidth TDBGrid1
End Sub
Private Sub TDBGrid1_DblClick()
InvertView TDBGrid1
End Sub
Public Sub AdjustViewColumnAndCaptionWidth(TDBGridX As TrueOleDBGrid80.TDBGrid, Optional VScrollWidth1 As Long = 330, Optional VScrollWidth2 As Long = 90)
TDBGrid1.ViewColumnWidth = TDBGrid1.Width - TDBGrid1.ViewColumnCaptionWidth - VBA.IIf(TDBGrid1.VScrollWidth > 0, VScrollWidth1, VScrollWidth2)
End Sub