Solved

Change row color in listview

Posted on 2014-03-30
6
535 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
Technology Partners: 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

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!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

636 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