public static void UpdateFOLV_add(FastObjectListView olv, ICollection Collection, bool ResizeCols = false, bool Follow = false)
        {
            Global_GUI.InvokeIFRequired(olv, () =>
            {
                try
                {
                    if (olv.Items.Count == 0)
                    {
                        olv.EmptyListMsg = "Loading...";
                    }

                    olv.Freeze();

                    olv.UpdateObjects(Collection);

                    if (olv.Items.Count > 0)
                    {
                        if (Follow)
                        {
                            olv.SelectedIndex = 0;                              //olv.Items.Count - 1;
                            olv.EnsureModelVisible(olv.SelectedObject);
                        }

                        //update column size only if did not restore folv state file or forced
                        if (olv.Tag == null || ResizeCols)
                        {
                            olv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                            olv.Tag = "resizedcols";
                        }
                    }
                    else
                    {
                        olv.EmptyListMsg = "Empty";
                    }
                }
                catch (Exception ex)
                {
                    Global.Log("Error: " + Global.ExMsg(ex));
                }
                finally
                {
                    olv.Unfreeze();
                }
            });
        }
        // ====================================================================
        // ALL FUNCTIONS HERE ARE GUI HELPER FUNCTIONS AND NOT UNIQUE TO AITOOL
        // NO direct UI interaction
        // ====================================================================

        public static void UpdateFOLV(FastObjectListView olv, IEnumerable Collection, bool ResizeCols = false)
        {
            Global_GUI.InvokeIFRequired(olv, () =>
            {
                olv.Freeze();

                try
                {
                    //olv.ClearObjects();

                    olv.Tag = null;

                    olv.SetObjects(Collection, true);

                    if (olv.Items.Count > 0)
                    {
                        //update column size only if did not restore folv state file or forced
                        if (olv.Tag == null || ResizeCols)
                        {
                            olv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                            olv.Tag = "resizedcols";
                        }
                    }
                    else
                    {
                        olv.EmptyListMsg = "Empty";
                    }
                }
                catch (Exception ex)
                {
                    Global.Log("Error: " + Global.ExMsg(ex));
                }
                finally
                {
                    olv.Unfreeze();
                }
            });
        }
Example #3
0
        public static void UpdateFOLV(FastObjectListView olv, IList objs,
                                      bool Follow = false,
                                      ColumnHeaderAutoResizeStyle ResizeColsStyle = ColumnHeaderAutoResizeStyle.None,
                                      bool FullRefresh     = false,
                                      bool UseSelected     = false,
                                      object SelectObject  = null,
                                      bool ForcedSelection = false,
                                      [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
                        {
                            //only select something if nothing is already selected
                            if (SelectObject != null && (ForcedSelection || (UseSelected && olv.SelectedObject == null)))
                            {
                                //use the given object as selected
                                olv.SelectedObject = SelectObject;  //olv.Items.Count - 1;
                                olv.EnsureModelVisible(olv.SelectedObject);
                            }
                            //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: " + ex.Msg());
                }
                finally
                {
                    olv.Unfreeze();
                    if (FullRefresh)
                    {
                        olv.Refresh();
                    }
                }
            });
        }