Hi,
I have a user control which contains ListView. I copy all
ListViewItems into a separate List<ListViewIt emcalled
unfilteredItems .
I am using a BackgroundWorke r to filter the ListView. When I access
this list in the DoWork Handler I am getting an
InvalidOperatio nException that
the List was not created by this thread. Is there a way to solve this
problem?
Here some Code
public partial class ListCtrl : UserControl
{
private IListCtrlFilter filter;
private BackgroundWorke r filterWorker;
private List<ListViewIt emunfilterdItem s = new
List<ListViewIt em>();
...
void filterWorker_Do Work(object sender, DoWorkEventArgs e)
{
BackgroundWorke r worker = sender as BackgroundWorke r;
List<ListViewIt emunfiltered = e.Argument as
List<ListViewIt em>;
if filter;!= null)
{
listView.Items. Clear();
foreach (ListViewItem item in unfiltered)
{
if (worker.Cancell ationPending)
return;
if (filter.Include (item))
worker.ReportPr ogress(0, item);
}
}
}
void filterWorker_Pr ogressChanged(o bject sender,
ProgressChanged EventArgs e)
{
listView.Items. Add(e.UserState as ListViewItem);
}
...
}
Thanks for every hint
I have a user control which contains ListView. I copy all
ListViewItems into a separate List<ListViewIt emcalled
unfilteredItems .
I am using a BackgroundWorke r to filter the ListView. When I access
this list in the DoWork Handler I am getting an
InvalidOperatio nException that
the List was not created by this thread. Is there a way to solve this
problem?
Here some Code
public partial class ListCtrl : UserControl
{
private IListCtrlFilter filter;
private BackgroundWorke r filterWorker;
private List<ListViewIt emunfilterdItem s = new
List<ListViewIt em>();
...
void filterWorker_Do Work(object sender, DoWorkEventArgs e)
{
BackgroundWorke r worker = sender as BackgroundWorke r;
List<ListViewIt emunfiltered = e.Argument as
List<ListViewIt em>;
if filter;!= null)
{
listView.Items. Clear();
foreach (ListViewItem item in unfiltered)
{
if (worker.Cancell ationPending)
return;
if (filter.Include (item))
worker.ReportPr ogress(0, item);
}
}
}
void filterWorker_Pr ogressChanged(o bject sender,
ProgressChanged EventArgs e)
{
listView.Items. Add(e.UserState as ListViewItem);
}
...
}
Thanks for every hint
Comment