I have a solution to set alternate row back color in a ListView control.
But the problem here is that the alternate row color gets applied to entire listview i.e. alternate row color also gets applied to rows that do not have the data.
How do I prevent this from happening.
Below is the code I am using:
Code:Private Sub AltLVBackground(lv As ListView, _ ByVal BackColorOne As OLE_COLOR, _ ByVal BackColorTwo As OLE_COLOR) Dim lSM As Byte Dim picAlt As PictureBox With lv If .View = lvwReport And .ListItems.Count Then Set picAlt = Me.Controls.Add("VB.PictureBox", "picAlt") lSM = .Parent.ScaleMode .Parent.ScaleMode = vbTwips .PictureAlignment = lvwTile lH = .ListItems(1).Height With picAlt .BackColor = BackColorOne .AutoRedraw = True .Height = lH * 2 .BorderStyle = 0 .Width = 10 * Screen.TwipsPerPixelX picAlt.Line (0, lH)-(.ScaleWidth, lH * 2), BackColorTwo, BF Set lv.Picture = .Image End With Set picAlt = Nothing Me.Controls.Remove "picAlt" lv.Parent.ScaleMode = lSM End If End With End Sub




Reply With Quote