Aug 17, 2010 10:35 AM
(This post was last modified: Aug 17, 2010 10:41 AM by ubbelol.)
So I read miharbis thread about making extensions for types (https://hackforums.net/showthread.php?tid=606044), and I couldn't find anyone releasing an extension (which I find very weird) so I thought, why not make one :p
This is a very simple extension, I had a mate on MSN today who asked for this just thing though.
Hopefully this will inspire more people to release extensions 😉
Alright so here's a little preview of what it does:
[IMG]http://i350.photobucket.com/albums/q408/ubbe12/backclr.gif[/IMG] (Color looks much better in reality)
Here's the code (2 alternatives, they both serve the same function)
Don't forget to import "System.Runtime.CompilerServices"!
Now you can use this method accordingly:
So say you want to color each 4th item black, you would do it like this:
If you want it to color each 2nd item with the color whitesmoke (in the example above), just leave it blank
Have fun and please post your own extensions. 😁
This is a very simple extension, I had a mate on MSN today who asked for this just thing though.
Hopefully this will inspire more people to release extensions 😉
Alright so here's a little preview of what it does:
[IMG]http://i350.photobucket.com/albums/q408/ubbe12/backclr.gif[/IMG] (Color looks much better in reality)
Here's the code (2 alternatives, they both serve the same function)
Don't forget to import "System.Runtime.CompilerServices"!
Code
<Extension()> Public Sub colorLv(ByVal lV As System.Windows.Forms.ListView, _
Optional ByVal backClr As Color = Nothing, _
Optional ByVal modVal As Integer = 2)
If Not lV.View = 1 Then Exit Sub
If backClr = Nothing Then backClr = Color.WhiteSmoke
For i = 0 To lV.Items.Count - 1
If (i Mod modVal = 0) Then lV.Items(i).BackColor = backClr
Next
End SubCode
<Extension()> Public Sub colorLv(ByVal lV As System.Windows.Forms.ListView, _
Optional ByVal backClr As Color = Nothing, _
Optional ByVal modVal As Integer = 2)
If Not lV.View = 1 Then Exit Sub
If backClr = Nothing Then backClr = Color.WhiteSmoke
For i = 0 To lV.Items.Count - 1 Step modVal
lV.Items(i).BackColor = backClr
Next
End SubNow you can use this method accordingly:
Code
listview1.colorLv(System.Color, Integer)So say you want to color each 4th item black, you would do it like this:
Code
listview1.colorLv(Color.Black, 4)If you want it to color each 2nd item with the color whitesmoke (in the example above), just leave it blank
Code
listview1.colorLv()Have fun and please post your own extensions. 😁
Probably coding some useless shit.


