hi how can i make list view like this ?

ListView1.Items(1).BackColor = Color.LightGray

Recommended Answers

All 3 Replies

Dim grp As ListViewGroup
 grp = ListView1.Groups.Add("String", "String")

 Dim item As ListViewItem = New ListViewItem(grp)
        Dim remain As Integer
        Math.DivRem(ListView1.Items.Count, 2, remain)
        If remain <> 0 Then
            item.BackColor = Color.White
            item.BackColor = Color.WhiteSmoke
        End If

        item.Text = "Item String"
        item.SubItems.Add("sub item" )


I use the Mod operator which returns the remainder.

Dim lvi As New ListViewItem
lvi.Text = "Hello"
If ListView1.Items.Count Mod 2 = 0 Then
    lvi.BackColor = Color.white
    lvi.BackColor = Color.LightGray
End If

if you wanna have such list view items you should make a listview group

Dim grp As ListViewGroup

then you need items and maybe subitems for each row that is included in your group

Dim item As ListViewItem = New ListViewItem(grp)

you must apply your property on your items
and at the end add that item into your listview

thats not hard to understand :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.