Solved

List views in VB.NET

Posted on 2009-05-19
4
170 Views
Last Modified: 2013-11-26
Afternoon,

I'm trying to change the row colour in a list view when the items become older than 30 days.  Well that may change i can play wiht that later but initially i though it would be simple, but the colour doesn't change.  Can anyone see what's wrong with my code?
LVReturns.Items.Clear()
        For Each ReturnItem In DS.Returns.Rows
            Dim LI As New ListViewItem
            Dim TimeSpan As TimeSpan
            Dim Age As Integer = 0
            TimeSpan = Now.Subtract(ReturnItem.SendDate)
            Age = TimeSpan.Days
            If Age > 30 Then
                LI.ForeColor = Color.Red
                LI.UseItemStyleForSubItems = True
            End If
            LI.Text = Convert.ToString(ReturnItem.ref)
            LI.SubItems.Add(ReturnItem.Name)
            LI.SubItems.Add(ReturnItem.SendDate)
            LI.SubItems.Add(Age)
            LI.SubItems.Add(ReturnItem.Item)
            LVReturns.Items.Add(LI)
        Next

Open in new window

0
Comment
Question by:nick210577
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24421832
Is this a ListView in ASP.NET or in WinForms? Seems to be the latter, as the UseItemStyleForSubItems  is not available on an ASP.NET listitem.

Are you sure your if-statement is ever hit? You can test by just changing only the very first list item and see if that works.


0
 
LVL 39

Assisted Solution

by:abel
abel earned 500 total points
ID: 24421858
In other words, suppose you do this, is then everything green?

LVReturns.Items.Clear()
        For Each ReturnItem In DS.Returns.Rows
            Dim LI As New ListViewItem
            Dim TimeSpan As TimeSpan
            Dim Age As Integer = 0
            TimeSpan = Now.Subtract(ReturnItem.SendDate)
            Age = TimeSpan.Days
            If Age > 30 Then
                LI.ForeColor = Color.Red
                LI.UseItemStyleForSubItems = True
            Else
                LI.ForeColor = Color.Green
                LI.UseItemStyleForSubItems = True
            End If
            LI.Text = Convert.ToString(ReturnItem.ref)
            LI.SubItems.Add(ReturnItem.Name)
            LI.SubItems.Add(ReturnItem.SendDate)
            LI.SubItems.Add(Age)
            LI.SubItems.Add(ReturnItem.Item)
            LVReturns.Items.Add(LI)
        Next

Open in new window

0
 

Author Closing Comment

by:nick210577
ID: 31582986
Thanks guys...

Embarrassingly i have a couple of LV's on this page and i'd added the code to the wrong one, and none of the lines met that criteria.  Adding the else/ forecolor green highlighted my mistake.  Thanks guys.
0
 
LVL 39

Expert Comment

by:abel
ID: 24422314
(from grading comment)
> Thanks guys...
You're welcome, I (abel) was only one person ;-)

> Embarrassingly i have a couple of LV's on this page and i'd added the code to the wrong > one, and none of the lines met that criteria. Adding the else/ forecolor green highlighted my mistake.

don't let your own mistakes (we all make them, don't feel embarrassed, that's what this site is for, have an extra pair of eyes) cloud your judgment in grading. Please review the 10pts must principle of EE for why this is.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question