CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Nov 2004
    Posts
    8

    List View alternate row back color

    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
    Last edited by HanneSThEGreaT; May 18th, 2010 at 10:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured