Solved

Change row color in listview

Posted on 2014-03-30
6
533 Views
Last Modified: 2014-03-31
I am not asking for the answer on this.  I want to make that very clear.  I am looking for direction on this.  What I need to know if its possible to do is look at a sql database and if the "Arrived" time is over 5 mins, change the color on the row of the list box.  Again I have not started working on this, I have some knowledge on how to change a row color on an individual item in the listview I just cant think of an efficent way to have a timer look at a database and see if the time on open calls are greater than 5 mins.  I am just looking for some help on this.  Any responses would be appreciated.  I am programing in VB.NET not C++
0
Comment
Question by:russell12
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39967230
Are you working with ASP.NET web site, Windows Forms, WPF...?
0
 
LVL 2

Author Comment

by:russell12
ID: 39967240
Winforms vs2013.  Coding in vb.net
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39967252
You should be able to set the ListViewItem.BackColor to what you need.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 39967291
If you could fetch the data at the beginning and STORE it in one of the rows, you'd only need to make one database call, and then have the timer compare the current time against stored data, somewhat like:


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ListView1.View = View.Details
        ' Create three items and three sets of subitems for each item. 
        Dim item1 As New ListViewItem("item1", 0)
        ' Place a check mark next to the item.
        item1.Checked = True
        item1.SubItems.Add(DateTime.Now.AddHours(1))
        item1.SubItems.Add("2")
        item1.SubItems.Add("3")
        Dim item2 As New ListViewItem("item2", 1)
        item2.SubItems.Add(DateTime.Now.AddSeconds(10))
        item2.SubItems.Add("5")
        item2.SubItems.Add("6")
        Dim item3 As New ListViewItem("item3", 0)
        ' Place a check mark next to the item.
        item3.Checked = True
        item3.SubItems.Add(DateTime.Now.AddHours(1))
        item3.SubItems.Add("8")
        item3.SubItems.Add("9")

        ' Create columns for the items and subitems. 
        ' Width of -2 indicates auto-size.
        ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
        ListView1.Columns.Add("Time", -2, HorizontalAlignment.Left)
        ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
        ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

        'Add the items to the ListView.
        ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})
        t.Interval = 1000
        AddHandler t.Tick, AddressOf OnTimedEvent
        t.Start()
    End Sub

    Private Sub OnTimedEvent(source As Object, e As EventArgs)
        For Each i As ListViewItem In ListView1.Items
            If DateTime.Now > DateTime.Parse(i.SubItems(1).Text) Then
                i.BackColor = Color.AliceBlue
            End If
        Next
    End Sub

Open in new window

0
 
LVL 2

Author Closing Comment

by:russell12
ID: 39968359
I can not believe i didnt think of doing it this way!  I appreciate your help.
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39968399
My pleasure, thanks for the quick feedback
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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