DBGrid的用法集锦:
DBGrid的用法集锦:1、如何修改DBGrid的列标题
可以使用Select语句指定标题,如:
Select f1 As [姓名] From db
但是这种方法有毛病,因为VB认为使用了As后,数据库就变成只读的了。
比较好的办法是利用DBGrid的Column的Caption,如:
DBGrid1.Columns(1).Caption = "姓名"
2、怎样把过滤过的数据在DBGRID上显示出来
下面是大致的代码:
Private Sub cmdFilter_Click()
On Error GoTo FilterErr
Dim recRecordset1 As Recordset, recRecordset2 As Recordset
Dim sFilterStr As String
If Data1.RecordsetType = vbRSTypeTable Then
Beep
MsgBox "不能过滤表记录集!", 48
Exit Sub
End If
Set recRecordset1 = Data1.Recordset '复制记录集
sFilterStr = InputBox("输入过滤器表达式:")
If Len(sFilterStr) = 0 Then Exit Sub
Screen.MousePointer = vbHourglass
recRecordset1.Filter = sFilterStr
Set recRecordset2 = recRecordset1.OpenRecordset(recRecordset1.Type) '建立过滤器
Set Data1.Recordset = recRecordset2 '赋值为初始记录集对象
Screen.MousePointer = vbDefault
Exit Sub
FilterErr:
Screen.MousePointer = vbDefault
MsgBox "错误:" & Err & "," & Err.Description
End Sub