473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alternate Colours [sic] In ListView

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
3 2188
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
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.com wrote in message
news:11******** **************@ i13g2000prf.goo glegroups.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
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******** ******@TK2MSFTN GP05.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2497
by: aznFETISH | last post by:
I have a list of links that I ue on my page, I alternate background colors for these links in a table, I usually do it using a DB but this list of link is manually added into the page so my question, is it possible to alternate the row colors automatic and have it created from a list of URL's?
4
3944
by: Els | last post by:
Hi, I would like an opinion on the following: I have a page which is made up of background-images with transparent linked images in front of it, which on hover show text in CSS popups. Due to appropriate alt text, anyone viewing the page with images turned off, will see the alt text instead, and on hover will see the popups.
3
4742
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
8
2243
by: Doug Laidlaw | last post by:
I tried to grab an image from a Web page the other day. It turned out that the page was made up of three horizontal bands, and part of the image was in each. One band was a JPEG, another was a GIF and I have forgotten what the main page was. Apart from lining up the parts of the image, there was no discrepancy in colours between the two...
7
5982
by: Matt B | last post by:
I have a need to alternate output row colour where not every row in the sequence is output, so I cannot base the colour on whether position() is odd or even. e.g. .... <xsl:for-each select="result"> <xsl:if test="@status = 'Pass'"> <tr><td>@name</td></tr> </xsl:if> <xsl:for-each>
4
2276
by: sconeek | last post by:
Hi all, I am generating a html based table with multiple rows of data coming in real time from a postgres DB. The underlying technology is java based however the front end is html. now i am unable to alternate the colour of every row so that the table is lot more readable. can anyone suggest a javascript or even a css script which will...
1
4342
by: Eric Lindsay | last post by:
I am trying to understand the differences between and uses of persistent, default and alternate styles. I have read http://www.w3.org/TR/REC-html40/present/styles.html section 14.3.2 on specifying external style sheets in link using combinations of rel and using or not using the title attribute. I think I sort of understand rel="alternate...
6
2420
by: sconeek | last post by:
hi all, my java servlet code has a foreach loop which automatically generates a HTML table with x number of rows. now my problem is that I would like the rows to be alternating in colour so that its a lot more easier to read. i have tried to implement a few approaches but everytime it fails. can somebody help me out with us and suggest a...
1
1458
by: Mr. B | last post by:
I've not programmed for a while in VB 2003... but I've decided to modlfiy a Project I have. Seems simple enough... I've a List Box... I fill it with about 30 lines of data (3-4 columns). What I want to do is to be able to List the ROWS of data either a RED or GREEN colour depending upon an IF statement. So... IF X =< myVariable then...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.