public virtual void BuildList(bool shouldPreserveState)
{
if (this.Frozen)
return;
this.ApplyExtendedStyles();
this.ClearHotItem();
int previousTopIndex = this.TopItemIndex;
Point currentScrollPosition = this.LowLevelScrollPosition;
IList previousSelection = new ArrayList();
Object previousFocus = null;
if (shouldPreserveState && this.objects != null) {
previousSelection = this.SelectedObjects;
OLVListItem focusedItem = this.FocusedItem as OLVListItem;
if (focusedItem != null)
previousFocus = focusedItem.RowObject;
}
IEnumerable objectsToDisplay = this.FilteredObjects;
this.BeginUpdate();
try {
this.Items.Clear();
this.ListViewItemSorter = null;
if (objectsToDisplay != null) {
// Build a list of all our items and then display them. (Building
// a list and then doing one AddRange is about 10-15% faster than individual adds)
List<ListViewItem> itemList = new List<ListViewItem>(); // use ListViewItem to avoid co-variant conversion
foreach (object rowObject in objectsToDisplay) {
OLVListItem lvi = new OLVListItem(rowObject);
this.FillInValues(lvi, rowObject);
itemList.Add(lvi);
}
this.Items.AddRange(itemList.ToArray());
this.Sort();
if (shouldPreserveState) {
this.SelectedObjects = previousSelection;
this.FocusedItem = this.ModelToItem(previousFocus);
}
this.RefreshHotItem();
}
} finally {
this.EndUpdate();
}
// We can only restore the scroll position after the EndUpdate() because
// of caching that the ListView does internally during a BeginUpdate/EndUpdate pair.
if (shouldPreserveState) {
this.RefreshHotItem();
// Restore the scroll position. TopItemIndex is best, but doesn't work
// when the control is grouped.
if (this.ShowGroups)
this.LowLevelScroll(currentScrollPosition.X, currentScrollPosition.Y);
else
this.TopItemIndex = previousTopIndex;
}
}