public static void UpdateFOLV(FastObjectListView olv, IList objs, bool Follow = false, ColumnHeaderAutoResizeStyle ResizeColsStyle = ColumnHeaderAutoResizeStyle.None, bool FullRefresh = false, bool UseSelected = false, object SelectObject = null, [CallerMemberName()] string memberName = null) { Global_GUI.InvokeIFRequired(olv, () => { try { int oldcnt = olv.Items.Count; if (oldcnt == 0) { olv.EmptyListMsg = "Loading..."; } //Debug.Print($"{DateTime.Now} - {memberName} > UpdateFOLV: {objs.Count} items, Follow={Follow}"); olv.Freeze(); //accessed from another thread if (FullRefresh) { olv.ClearCachedInfo(); olv.ClearObjects(); } if (FullRefresh || olv.Items.Count == 0) //full refresh of new objects { olv.SetObjects(objs, true); } else { olv.AddObjects(objs); //minimize list changes } if (olv.Items.Count > 0) { if (Follow) { if (SelectObject != null && UseSelected) { //use the given object as selected olv.SelectedObject = SelectObject; //olv.Items.Count - 1; } else if (SelectObject == null && UseSelected && olv.IsFiltering && olv.GetItemCount() > 0) { //use the last filtered object as the selected object olv.SelectedObject = olv.FilteredObjects.Cast <object>().Last(); } else if (!olv.IsFiltering) { //just use the last object given to us olv.SelectedObject = objs[objs.Count - 1]; //olv.Items.Count - 1; } if (olv.SelectedObject != null) { olv.EnsureModelVisible(olv.SelectedObject); } } else { //if (SelectObject != null && UseSelected) //{ // //use the given object as selected // olv.SelectedObject = SelectObject; //olv.Items.Count - 1; //} //else if (SelectObject == null && UseSelected && olv.IsFiltering && olv.GetItemCount() > 0) //{ // //use the last filtered object as the selected object // olv.SelectedObject = olv.FilteredObjects.Cast<object>().First(); //} //else if (!olv.IsFiltering && UseSelected) //{ // //just use the last object given to us // olv.SelectedObject = objs[0]; //olv.Items.Count - 1; //} } //update column size only if did not restore folv state file or forced if (olv.Tag == null) { olv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); olv.Tag = "resizedcols"; } else if (ResizeColsStyle != ColumnHeaderAutoResizeStyle.None) { olv.AutoResizeColumns(ResizeColsStyle); olv.Tag = "resizedcols"; } } else { olv.EmptyListMsg = "Empty"; } } catch (Exception ex) { Log("Error: " + Global.ExMsg(ex)); } finally { olv.Unfreeze(); if (FullRefresh) { olv.Refresh(); } } }); }