public virtual bool RestoreState(byte[] state)
{
using (MemoryStream ms = new MemoryStream(state)) {
BinaryFormatter deserializer = new BinaryFormatter();
ObjectListViewState olvState;
try {
olvState = deserializer.Deserialize(ms) as ObjectListViewState;
} catch (System.Runtime.Serialization.SerializationException) {
return false;
}
// The number of columns has changed. We have no way to match old
// columns to the new ones, so we just give up.
if (olvState == null || olvState.NumberOfColumns != this.AllColumns.Count)
return false;
if (olvState.SortColumn == -1) {
this.LastSortColumn = null;
this.LastSortOrder = SortOrder.None;
} else {
this.LastSortColumn = this.AllColumns[olvState.SortColumn];
this.LastSortOrder = olvState.LastSortOrder;
}
for (int i = 0; i < olvState.NumberOfColumns; i++) {
OLVColumn column = this.AllColumns[i];
column.Width = (int)olvState.ColumnWidths[i];
column.IsVisible = (bool)olvState.ColumnIsVisible[i];
column.LastDisplayIndex = (int)olvState.ColumnDisplayIndicies[i];
}
// ReSharper disable RedundantCheckBeforeAssignment
if (olvState.IsShowingGroups != this.ShowGroups)
// ReSharper restore RedundantCheckBeforeAssignment
this.ShowGroups = olvState.IsShowingGroups;
if (this.View == olvState.CurrentView)
this.RebuildColumns();
else
this.View = olvState.CurrentView;
}
return true;
}