私は次のようにListViewにアイテムを追加しています:
private int AddThreadToListView(int threadNumber, string proxy, string query, string page, string links)
{
int index = 0;
listView1.SuspendLayout();
Invoke(new MethodInvoker(
delegate
{
string[] row1 = { proxy, query, page, links };
ListViewItem item = new ListViewItem();
listView1.Items.Add(threadNumber.ToString()).SubItems.AddRange(row1);
index = listView1.Items.Count - 1;
}
));
if ((listView1.Items.Count % 1000) == 0)
{
listView1.ResumeLayout();
listView1.SuspendLayout();
}
listView1.ResumeLayout();
return index;
}
次に、アイテムのインデックスを追跡して、スレッド内から戻って更新できるようにします。(それはうまくいきます)。
ただし、問題は、これらのアイテムを削除し始めると、何らかの理由でインデックスが変更されることです。
これが私の更新と削除のメソッドです:
private void UpdateThreadListView(int threadNumber, string proxy, string query, string page, string links)
{
Invoke(new MethodInvoker(
delegate
{
listView1.BeginUpdate();
ListViewItem itm = listView1.Items[threadNumber];
itm.SubItems[1].Text = proxy;
itm.SubItems[2].Text = query;
itm.SubItems[3].Text = page;
itm.SubItems[4].Text = links;
listView1.EndUpdate();
}
));
}
private void RemoveThreadListView(int threadNumber)
{
Invoke(new MethodInvoker(
delegate
{
listView1.BeginUpdate();
listView1.Items[threadNumber].Remove();
listView1.EndUpdate();
}
));
}
どういうわけか、変更されないインデックス、作成されたリストビューアイテムごとに一意のインデックスが必要です。
どうすればこれを達成できますか?