|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
下面代码如何修改成
ListView1.ListItems.SubItems(7)=0 ,的时候, 整行变成灰色
Private Sub UserForm_Initialize()
a = Array(40, 160, 80, 210, 60, 0, 60, 50, 60, 130, 100)
Set cnn = New ADODB.Connection
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "\date.mdb;Jet OleDb:DataBase Password=123456"
sql = "select * from 商品表 "
Set rs = New ADODB.Recordset
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
ReDim arr(1 To rs.Fields.Count)
On Error Resume Next
With ListView1
.ColumnHeaders.Clear
.View = lvwReport
.FullRowSelect = True
.Gridlines = True
For i = 0 To rs.Fields.Count - 1
If i > 3 Then '3是第五列
.ColumnHeaders.add , , rs.Fields(i).Name, a(i), lvwColumnCenter '从第5列起居中
Else
.ColumnHeaders.add , , rs.Fields(i).Name, a(i)
End If
arr(i + 1) = rs.Fields(i).Name
Next i
End With
rs.MoveFirst
Call 显示数据
End Sub
Sub 显示数据() '显示数据
Dim i&, j&, s$, t$, sql$
On Error Resume Next
If TTB.Value = "" Then ListView1.ListItems.Clear
t = Me.Controls("TTB").Text
If Len(t) Then s = s & " and UCase(" & arr(4) & ") like '%" & UCase(t) & "%'" 'arr(4)(商品型号、类型为搜索项)
sql = "select * from 商品表"
If Len(s) Then sql = sql & " where " & Mid(s, 6)
Set rs = New ADODB.Recordset
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
With ListView1
.ListItems.Clear
For i = 1 To rs.RecordCount
.ListItems.add , , rs.Fields(0).Value
For j = 1 To rs.Fields.Count - 1
.ListItems(i).SubItems(j) = rs.Fields(j).Value
Next
rs.MoveNext
Next
End With
rs.MoveFirst
End Sub
|
|