Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Alternate Colours [sic] In ListView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Charles Law - 14 Oct 2007 23:59 GMT
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
Phillip Taylor - 16 Oct 2007 16:21 GMT
> 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
[quoted text clipped - 15 lines]
>
> 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
Charles Law - 17 Oct 2007 01:39 GMT
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

>> 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
[quoted text clipped - 28 lines]
>    yellow = not yellow
> Next
Charles Law - 19 Oct 2007 18:48 GMT
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

> 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
[quoted text clipped - 15 lines]
>
> Charles

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.