public static void SetState(ListView list, ListState state) { if (state.fTopIndex != -1 && state.fTopIndex < list.Items.Count) { list.TopItem = list.Items[state.fTopIndex]; } if (state.fSelectedIndex != -1 && state.fSelectedIndex < list.Items.Count) { list.SelectedIndices.Add(state.fSelectedIndex); } }
public static ListState GetState(ListView list) { ListState listState = new ListState() { fTopIndex = list.Items.IndexOf(list.TopItem), fSelectedIndex = -1 }; if (list.SelectedIndices.Count != 0) { listState.fSelectedIndex = list.SelectedIndices[0]; } return(listState); }