Solved

Change row color in listview

Posted on 2014-03-30
6
532 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 37
Code enhancement 4 32
Error building VS2105 solution from repository 1 33
VB.net VSTO Excel Ribbon error 4 10
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

740 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