我有一个 ListView,我用一个循环一个一个地向它添加项目
这个 ListView 有 CheckBoxes
在该循环中,我决定是否应检查复选框
问题是是否应检查太多复选框添加项目太慢
这是代码:
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);
}
}
我怎样才能让它更快?