Click here to Skip to main content
13,095,218 members (82,085 online)
Rate this:
Please Sign up or sign in to vote.
See more:
""Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on.""
I found this problem. How can I solve it.
My code:

ListViewItem item1 = new ListViewItem(sKW,0);


listView1.Items.AddRange(new ListViewItem[]{item1});

for(int i = 0 ; i < listView1.Items.Count;i++)

string sKW = listView1.Items[i].SubItems[0].Text; // i got error here
progressBar1.Value = i+1;
Posted 25-Mar-13 21:54pm
Updated 25-Mar-13 22:03pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Accessing UI element from different thread is not possible. Most possibly your code is running under different thread. If so then you can change your code and run it under main (ui) thread. If you need to access it from different thread then simply read the value as you normally do. Only to update the control, you need to switch to GUI thread.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100