Change color of listview items on a seperate thread

Posted on 2009-12-22
Last Modified: 2012-05-08
How do I change the color of a listview item, if the listview is on a different thread than the function that's calling the color change?

My code for the listview is:
OrderView.Items.Item(ListViewIndex).ForeColor = Color.Blue

Thanks for your help!
Question by:slightlyoff
    LVL 1

    Accepted Solution

    In order to interact with a control from a thread other then the one that created the control, you must use either the Control.Invoke or Control.BeginInvoke method.

        Private Delegate Sub Invoker()

        Private Sub Update()
            If OrderView.InvokeRequired Then
                Dim method As New Invoker(AddressOf Update)
                OrderView.Items.Item(ListViewIndex).ForeColor = Color.Blue
            End If
        End Sub

    LVL 1

    Author Closing Comment

    Thank you!  I appreciate the help!

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 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

    17 Experts available now in Live!

    Get 1:1 Help Now