// 在末尾增加一个记忆 public void Add(ListView list, T state, bool bDelay = false) { while (this.Count > this.Index + 1) { this.RemoveAt(this.Index + 1); } ListItems <T> items = new ListItems <T>(); items.State = state; if (bDelay == false) { foreach (ListViewItem item in list.Items) { items.Add(item); } } else { items.Delay = true; } this.Add(items); this.Index++; }
// 刷新当前记忆 public void Refresh(ListView list, T state, bool bDelay = false) { #if NO if (this.Index + 1 < this.Count) { ListItems <T> items = this[this.Index + 1]; items.State = state; if (bDelay == false) { items.Clear(); foreach (ListViewItem item in list.Items) { items.Add(item); } } else { // 即便以前有内容,也要清除,以便以后可以延迟装载 items.Clear(); items.Delay = true; } } #endif if (this.Index < this.Count && this.Index != -1) { ListItems <T> items = this[this.Index]; items.State = state; if (bDelay == false) { items.Clear(); foreach (ListViewItem item in list.Items) { items.Add(item); } } else { // 即便以前有内容,也要清除,以便以后可以延迟装载 items.Clear(); items.Delay = true; } } }
void DelaySet(ListView list, T state, int index) { // 滞后加入当前事项 if (index < this.Count) { ListItems <T> items = this[index]; if (items.Delay == true) { // 滞后加入 items.State = state; items.Clear(); foreach (ListViewItem item in list.Items) { items.Add(item); } items.Delay = false; } } }
// 看看是否已经为滞后,需要补充加入 public void EnsureAdd(ListView list, T state) { if (this.Index < 0 || this.Index >= this.Count) { return; } #if NO ListItems <T> items = this[this.Index]; if (items.Delay == true) { // 滞后加入 items.State = state; items.Clear(); foreach (ListViewItem item in list.Items) { items.Add(item); } items.Delay = false; } #endif DelaySet(list, state, this.Index); }