Solved

Change row color in listview

Posted on 2014-03-30
6
522 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
  • 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now