I have a ListViewItem that contains many items by default all the item checked.
I want to write a function that will get list of items that need to be checked.
public void NewCheckSecurities(SecurityList oSecurities)
{
// error checking
if (oSecurities == null || oSecurities.Count == 0)
{
return;
}
// check sent securities
ListView.ListViewItemCollection oItems = m_lsvSecurities.Items;
if (oItems != null)
{
int i = 1;
foreach (ListViewItem oItem in oItems)
{
bool bFind = oSecurities.FindSecurity((oItem.Tag as SecurityItem).Security.Symbol) != null;
if(bFind)
{
oItem.Checked = true;
}
else
{
oItem.Checked = false;
}
}
}
}
oSecurities got 5 securities that I want to checked.
oItems size - 2800 items
In order to check the problem, I had to split the function into 2 parts (find, checked).
The first part is a loop that runs through all the items and just makes bFind to true or false.
When I add the second part with
if(bFind)
{
oItem.Checked = true;
}
else
{
oItem.Checked = false;
}
its work but too slow.
when the code doing oItem.Checked to true or false foreach oItem in oItems is took long time.
there is a way to do this faster?

The issue is most likely caused by the component redrawing itself after every update.
This can often be sped up by telling the Form to pause visual updates while you are making changes, as follows:
It should run in a place where
thisequals the Form. Or if you prefer to run it somewhere else then you'll need to pass the Form as a parameter to that method and call Suspend...+Resume... there.