// 将 index + 1 位置的内容提取出来,当前位置改到 index + 1 public void Forward(ListView list, T state) { if (this.Index + 1 >= this.Count) { return; } DelaySet(list, state, this.Index); list.Items.Clear(); this.Index++; ListItems <T> items = this[this.Index]; foreach (ListViewItem item in items) { list.Items.Add(item); } if (this.StateChanged != null) { StateChangedEventArgs e = new StateChangedEventArgs(); e.State = items.State; this.StateChanged(this, e); } }
// 在末尾增加一个记忆 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); }