Alternate Colours [sic] In ListView

C

Charles Law

Ok. I haven't been around for a while, so I hope someone will come to my
rescue. I thought I had done this years ago, but I have scoured my code
snippets and can't find it.

I want my ListView control to have a different background colour on
alternate rows. I'm using VS2005.

Firstly, I'm surprised that I can't do it out of the box. But secondly, I
can't find a really simple one-liner that let's me do it by overriding
something.

I could owner draw, or custom draw, but these seem to be the hammer to crack
the nut. Is there a way to do this easily?

Failing that, what is the preferred way?

TIA

Charles
 
P

Phillip Taylor

Ok. I haven't been around for a while, so I hope someone will come to my
rescue. I thought I had done this years ago, but I have scoured my code
snippets and can't find it.

I want my ListView control to have a different background colour on
alternate rows. I'm using VS2005.

Firstly, I'm surprised that I can't do it out of the box. But secondly, I
can't find a really simple one-liner that let's me do it by overriding
something.

I could owner draw, or custom draw, but these seem to be the hammer to crack
the nut. Is there a way to do this easily?

Failing that, what is the preferred way?

TIA

Charles

You can do it out of the box.

dim yellow as boolean = true
For each lvi as ListViewItem in lvItems
if (yellow) then
lvi.backcolor = color.yellow
else
lvi.backcolor = color.white
end if
yellow = not yellow
Next
 
C

Charles Law

Hi Phillip

Thanks for the response.

What happens when I add an item? Does it get the correct background
according to whether the new row is odd or even?

In addition, I would like the grid to have alternate colours for the rows,
irrespective of whether there are any items in the list.

Charles
 
C

Charles Law

I should add that I want the background of alternate rows coloured
differently, even when there are no items in the list view. So, setting the
background colour of each item doesn't work.

Does anyone have an idea?

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top