By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Alternate Colours [sic] In ListView

P: n/a
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
Oct 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Oct 14, 11:59 pm, "Charles Law" <bl...@nowhere.comwrote:
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

Oct 16 '07 #2

P: n/a
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
"Phillip Taylor" <Ph*****************@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Oct 14, 11:59 pm, "Charles Law" <bl...@nowhere.comwrote:
>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

Oct 17 '07 #3

P: n/a
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
"Charles Law" <bl***@nowhere.comwrote in message
news:uQ**************@TK2MSFTNGP05.phx.gbl...
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


Oct 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.