vb中listview控件怎么设置某一行的背景色

2024年11月30日 18:54
有1个网友回答
网友(1):

刚好我写了一个,因为我自己需要用到呵..不过老实说,listview有选中的效果,那个应该 就能满足你的要求:

Option Explicit
Private WithEvents bc As PictureBox

Private Sub Command1_Click()
Call SetLineBackColor(ListView1, 3, &HE0E0E0)
End Sub

Public Sub SetLineBackColor(Lv As ListView, LvLineCount As Long, LVBC As Long)'分别是listview的名称,第几行,背景色
Lv.Parent.ScaleMode = vbTwips
If bc Is Nothing Then
Set bc = Controls.Add("VB.PictureBox", "picbg")
End If
With bc
.Visible = True
.BackColor = Lv.BackColor
.ScaleMode = vbTwips
.BorderStyle = vbBSNone
.AutoRedraw = True
.Visible = False
.Width = Lv.Width
.Height = Lv.ListItems(1).Height * (LvLineCount + 1)
.ScaleHeight = LvLineCount + 1
.ScaleWidth = 1
.DrawWidth = 1
End With
bc.Line (0, LvLineCount - 1)-(1, LvLineCount), LVBC, BF
Lv.Picture = bc.Image
End Sub