|
-
Nov 27th, 2005, 09:05 PM
#1
Thread Starter
Hyperactive Member
alternate listview row color
how to make the row of listview to have an alternate color??
-
Nov 27th, 2005, 10:03 PM
#2
Hyperactive Member
Re: alternate listview row color
set the color of the listviewitem, not the listview:
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lv1 As New ListView
lv1.View = View.Details
lv1.Columns.Add("Column1", 120, HorizontalAlignment.Left)
lv1.Dock = DockStyle.Fill
For i As Integer = 0 To 15
Dim lvi As New ListViewItem("Item " & i + 1)
lvi.BackColor = Color.FromArgb(255, 255 - (i * 16), 255 - (i * 16), i * 16)
lvi.ForeColor = Color.FromArgb(255, i * 16, 255 - (i * 16), 255 - (i * 16))
lv1.Items.Add(lvi)
Next
Me.Controls.Add(lv1)
End Sub
-
Nov 27th, 2005, 10:12 PM
#3
Re: alternate listview row color
It would be a pain in the butt if your ListView is sortable, because you need to set the BackColor of each Item and then they will probably be out of order if sorted. You may be able to find an inherited ListView that already includes that functionality but I couldn't in a quick search. You could just create a method, either in a form or in an inherited ListView that alternately set the Item BackColors:
VB Code:
Private Sub SetAlternateItemColours()
For i As Integer = 0 To myListView.Items.Count - 1 Step 1
If i Mod 2 = 0 Then
myListView.Items(i).BackColor = Colors.Red
Else
myListView.Items(i).BackColor = Colors.Blue
End If
Next i
End sub
You would then make sure this method was called every time the data in the ListView changed, including when it was sorted. I haven't tested the performance of this code with a large number of Items, mind you.
-
Aug 20th, 2012, 03:00 AM
#4
Member
Re: alternate listview row color
thanks john useful tread....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|