We help IT Professionals succeed at work.

WPF Browser Application

thecruz
thecruz asked
on
485 Views
Last Modified: 2012-02-10
I'm trying to loop through items in a ListView control to match a content string, but when it tries to loop for the first time i get the following error:

Please help

Unable to cast object of type 'System.String' to type 'System.Windows.Controls.ListViewItem'.

this is the code i'm running:

if (tcpClientC.Connected)
                {
                    ItemCollection items = lstView.Items;
                    foreach (System.Windows.Controls.ListViewItem node in items)
                    {
                        if (node.Content == host + ":" + IpPort)
                        {
                            //node.ForeColor = Color.Green;
                            node.Background = new LinearGradientBrush(Colors.Green, Colors.SlateBlue, 90);
                        }
                    }
                    return true;
                }

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for your reply.  How would be able to turn the forground of the node to a different color if it matches?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
That would be a different question.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.