在网上找了个例子,
但是我用这个例子在AC中调试,却不能行.
我也贴出来,请高人一并看看.
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim itmX As ListItem
Dim ColHead As ColumnHeader
ListView1.ColumnHeaders.Add , , "This is vb ListView"
ListView1.ColumnHeaders(1).Width = 3000
For j = 1 To 20
Set itmX = ListView1.ListItems.Add()
itmX.Text = "Number" & CStr(j)
Next j
Call ListViewColor(Me, ListView1)
End Sub
Public Function ListViewColor(ByRef frmName As Form, ByRef ListName As ListView, _
Optional N1Color As Long = &HFFFFFF, _
Optional N2Color As Long = &HFFC0C0) As Long
On Error GoTo errorHand
Dim iHeight As Double
Dim iNull As Boolean
Dim itmX As ListItem
Dim PicName As PictureBox
Set PicName = frmName.Controls.Add("vb.PictureBox", "Neshcy", frmName)
If ListName.ListItems.Count <= 0 Then
Set itmX = ListName.ListItems.Add()
itmX.Text = "test........"
iNull = True
End If
With PicName
.AutoRedraw = True
.ScaleMode = vbTwips
.Font = ListName.Font
.BorderStyle = 1
.Appearance = 0
iHeight = ListName.ListItems(1).Height
.Height = iHeight * 2 + 30
End With
With ListName
PicName.Line (0, 0)-(.Width, iHeight), N1Color, BF
PicName.Line (0, iHeight)-(.Width, iHeight * 2), N2Color, BF
.PictureAlignment = lvwTile
.Picture = PicName.Image
If iNull = True Then
.ListItems.Clear
End If
End With
frmName.ScaleMode = vbTwips
errorHand:
Exit Function
End Function
ListViewColor函数解说:
frmName 要执行的窗体(frm)名称
ListName 要执行的ListView名称
N1Color 第一条可选颜色值;如果变动请在Optional N1Color As Long = &HFFFFFF 其中的&HFFFFFF改为什么`自己喜欢就改什么
N2Color 第二条可选颜色值;如果变动请在Optional N2Color As Long = &HFFC0C0 其中的&HFFC0C0改为什么`自己喜欢就改什么