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.
Well, this a rather clever and unconventional way of coloring rows alternately.
I have attached a little sample (got it from the web somewhere), which uses customdrawing and subclassing to achieve back-coloring. Can be adapted easily to alternately color the rows.
Well, I don't have a sample with a dll. Why do you want a dll? The sample I gave does not need any dll. Everything is self contained within the project. No dll reqired.
Did you try the sample at all?
Or maybe I do not understand you corrctly concerning the dll...
Well the reason I am using DLL because we have multiple projects ( exes) which are interlinked and use user controls, dll etc. All projects have list views in them.
I wanted a single source of applying alternate row coloring to ease the process of applying and later if someone wants to change the alternate row colors it can be done easily.
Would appreciate if you can provide a sample source using dll
It is not easy to write a standard dll with VB6.
However you could write an ActiveX-dll. The idea would be to write a class of a ListViewColorExtender object provided by this dll. You'd have then to instantiate such an object for each ListView you want to color.
In the end, if you want to use this within different projects, you'd have to change their code anyway. There is no chance of writing a dll which automatically does this coloring in any of your projects.
If you look at the sample project, all relevant code is in Module1. You only have to add that module to your project and make the apropriate calls in your code.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.