I have a ListView and i add items to it one-by-one with a loop
This ListView has CheckBoxes
In that loop i decide whether checkbox should be checked or not
Problem is if too many checkboxes should be checked adding items is too slow
Here is the code:
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow drow = dt.Rows[i];
// Only row that have not been deleted
if (drow.RowState != DataRowState.Deleted && int.Parse(drow["season"].ToString()) != 0)
{
ListViewItem lvi = new ListViewItem(drow["episode_name"].ToString());
lvi.SubItems.Add(drow["first_aired"].ToString());
lvi.SubItems.Add(drow["episode"].ToString());
lvi.SubItems.Add(drow["season"].ToString());
lvi.SubItems.Add(drow["rating"].ToString());
lvi.SubItems.Add(drow["episode_id"].ToString());
if (bool.Parse(drow["watched"].ToString()))
{
lvi.Checked = true; //this is the problem, when i remove it, adding is fast
}
else {
lvi.Checked = false;
}
episodesList.Items.Add(lvi);
}
}
How can i make it faster?