Example #1
0
        public static void ConfigureFOLV(FastObjectListView FOLV, Type Cls,
                                         System.Drawing.Font Fnt        = null,
                                         ImageList ImageList            = null,
                                         string PrimarySortColumnName   = "",
                                         SortOrder PrimarySortOrder     = SortOrder.Ascending,
                                         string SecondarySortColumnName = "",
                                         SortOrder SecondarySortOrder   = SortOrder.Ascending,
                                         List <string> FilterColumnList = null,
                                         Color Clr       = new Color(),
                                         int RowHeight   = 0,
                                         bool ShowGroups = false,
                                         bool GridLines  = true)
        {
            //Global_GUI.InvokeIFRequired(FOLV, () =>
            //{

            try
            {
                FOLV.AllowColumnReorder      = true;
                FOLV.CopySelectionOnControlC = true;
                FOLV.FullRowSelect           = true;
                FOLV.GridLines     = GridLines;
                FOLV.HideSelection = false;
                FOLV.IncludeColumnHeadersInCopy = true;
                FOLV.OwnerDraw = true;
                FOLV.SelectColumnsOnRightClick          = true;
                FOLV.SelectColumnsOnRightClickBehaviour = ObjectListView.ColumnSelectBehaviour.InlineMenu;
                FOLV.SelectedColumnTint          = Color.LawnGreen;
                FOLV.ShowCommandMenuOnRightClick = true;
                FOLV.ShowFilterMenuOnRightClick  = true;
                FOLV.ShowGroups                    = false;
                FOLV.ShowImagesOnSubItems          = true;
                FOLV.ShowItemCountOnGroups         = true;
                FOLV.ShowItemToolTips              = true;
                FOLV.ShowSortIndicators            = true;
                FOLV.SortGroupItemsByPrimaryColumn = true;
                FOLV.TintSortColumn                = true;
                FOLV.UseFiltering                  = true;
                FOLV.UseHyperlinks                 = true; //may cause column save/restore error?
                FOLV.CellEditActivation            = ObjectListView.CellEditActivateMode.DoubleClick;
                FOLV.UseCellFormatEvents           = true;
                FOLV.UseNotifyPropertyChanged      = true;

                if (ImageList != null)
                {
                    FOLV.SmallImageList = ImageList;
                }

                if (Fnt != null)
                {
                    FOLV.Font = Fnt;
                }
                else
                {
                    FOLV.Font = new Font("Consolas", 8, FontStyle.Regular);
                }

                if (Clr.IsEmpty)
                {
                    FOLV.ForeColor = Clr;
                }

                object[] IIProps2 = Cls.GetProperties(); //Cls.GetType().GetProperties

                //if (IIProps2.Length == 0)
                //    IIProps2 = Cls.GetFields();

                // Uncomment this to see a fancy cell highlighting while editing
                EditingCellBorderDecoration EC = new EditingCellBorderDecoration(true);
                EC.UseLightbox = true;

                FOLV.AddDecoration(EC);
                FOLV.BuildList();
                int colcnt = 0;

                //for (int i = 0; i < IIProps2.Length; i++)
                //{
                //    object ei = IIProps2[i];

                //}

                foreach (PropertyInfo ei in IIProps2)
                {
                    if (typeof(IEnumerable).IsAssignableFrom(ei.PropertyType) && !(ei.PropertyType.Name == "String"))
                    {
                        continue;
                    }
                    else if (ei.PropertyType.Name == "Object")
                    {
                        continue;
                    }

                    colcnt = colcnt + 1;
                    OLVColumn cl = new OLVColumn();
                    if (FOLV.SmallImageList != null)
                    {
                        if (string.Equals(FOLV.Name, "folv_history", StringComparison.OrdinalIgnoreCase))
                        {
                            if (colcnt == 1)
                            {
                                cl.ImageGetter = GetImageForHistoryList;
                            }
                            else if (ei.Name == "IsPerson")
                            {
                                cl.ImageGetter             = GetImageForHistoryListPerson;
                                cl.AspectToStringConverter = delegate(object x)
                                {
                                    return(String.Empty);
                                };
                            }
                            else if (ei.Name == "Success")
                            {
                                cl.ImageGetter             = GetImageForHistoryListSuccess;
                                cl.AspectToStringConverter = delegate(object x)
                                {
                                    return(String.Empty);
                                };
                            }
                        }
                        else if (string.Equals(FOLV.Name, "FOLV_AIServers", StringComparison.OrdinalIgnoreCase))
                        {
                            if (colcnt == 1)
                            {
                                cl.ImageGetter = GetImageForAIServerList;
                            }
                        }
                        else if (string.Equals(FOLV.Name, "FOLV_Cameras", StringComparison.OrdinalIgnoreCase))
                        {
                            if (colcnt == 1)
                            {
                                cl.ImageGetter = GetImageForCameraList;
                            }
                        }
                        //else if (FOLV.Name == "FOLV_BlocklistViewer" && ei.Name == "RegionalInternetRegistry")
                        //{
                        //	cl.ImageGetter = GetImageForBlocklistViewerRIR;
                        //}
                        //else if (FOLV.Name == "FOLV_Apps" && colcnt == 1)
                        //{
                        //	cl.ImageGetter = GetImageForProdList;
                        //}
                    }
                    //cl.AspectName = ei.Name
                    cl.UseFiltering = true;
                    cl.Searchable   = true;
                    cl.Text         = ei.Name;
                    cl.Name         = ei.Name;

                    cl.DataType   = ei.PropertyType;
                    cl.AspectName = ei.Name;

                    if (cl.Name == "Func" || ei.PropertyType.Name == "Int64" || ei.PropertyType.Name == "Int32" || ei.PropertyType.Name == "Timespan")
                    {
                        cl.TextAlign = HorizontalAlignment.Right;
                    }

                    if (ei.Name == "UniqueID" || ei.Name == "FoundElementList")
                    {
                        cl.MinimumWidth = 0;
                        cl.MaximumWidth = 0;
                        cl.Width        = 0;
                    }
                    else
                    {
                        cl.MinimumWidth = 50;
                        //cl.MaximumWidth = 20000
                        //cl.Width = -2
                    }

                    if (ei.Name.IndexOf("url", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        cl.Hyperlink = true;
                    }

                    if ((ei.Name.Has("percent") || ei.Name.Has("threshold") || ei.Name.Has("confidence")) && (ei.PropertyType == typeof(double) || ei.PropertyType == typeof(int) || ei.PropertyType == typeof(float)))
                    {
                        cl.AspectToStringFormat = "{0:0.#}%";
                    }

                    //if (ei.PropertyType == typeof(ThreadSafe.Boolean))
                    //{
                    //    if (FOLV.Name == "FOLV_AIServers")
                    //    {
                    //        cl.AspectGetter = delegate (object rowObject)
                    //        {
                    //            bool ret = false;
                    //            ClsURLItem obj = (ClsURLItem)rowObject;
                    //            if (ei.Name == "Enabled")
                    //            {
                    //                ret = obj.Enabled.ReadFullFence();
                    //            }
                    //            else if (ei.Name == "InUse")
                    //            {
                    //                ret = obj.InUse.ReadFullFence();
                    //            }
                    //            else
                    //            {
                    //                int test = 0;
                    //            }
                    //            return ret;
                    //        };

                    //        cl.DataType = typeof(bool);
                    //        cl.CheckBoxes = true;
                    //    }

                    //}
                    //if (ei.Name == "Enabled")
                    //{
                    //    int test = 0;
                    //}

                    //if (ei.PropertyType == typeof(Boolean))
                    //{
                    //    cl.CheckBoxes = true;
                    //    cl.IsEditable = false;
                    //}


                    if (string.Equals(ei.Name, PrimarySortColumnName, StringComparison.OrdinalIgnoreCase))
                    {
                        FOLV.PrimarySortColumn = cl;
                        FOLV.PrimarySortOrder  = PrimarySortOrder; //SortOrder.Descending

                        //cl.ImageGetter = AddressOf GetImageFromProd
                    }
                    if (string.Equals(ei.Name, SecondarySortColumnName, StringComparison.OrdinalIgnoreCase))
                    {
                        FOLV.SecondarySortColumn = cl;
                        FOLV.SecondarySortOrder  = SecondarySortOrder; //SortOrder.Descending
                    }

                    FOLV.AllColumns.Add(cl);  //Columns vs AllColumns?
                }

                //restore column state if it exists
                FOLVRestoreState(FOLV);

                //OLV.RebuildColumns()
                FOLV.Refresh();
                FOLV.BuildList();
                FOLV.RebuildColumns();

                //Application.DoEvents();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
            }

            //});
        }
Example #2
0
        public static bool FOLVRestoreState(FastObjectListView FOLV)
        {
            bool Ret = false;

            try
            {
                string Filename = Path.Combine(Path.GetDirectoryName(AppSettings.Settings.SettingsFileName), $"ListSaveState-{FOLV.Name}.JSON");

                if (!File.Exists(Filename))
                {
                    return(false);
                }

                FOLVObjectListViewState olvState = Global.ReadFromJsonFile <FOLVObjectListViewState>(Filename);

                // 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 != FOLV.AllColumns.Count)
                {
                    Log("Debug: olvState Is null OrElse olvState.NumberOfColumns <> FOLV.AllColumns.Count.");
                    return(false);
                }

                if (olvState.SortColumn == -1)
                {
                    FOLV.PrimarySortColumn = null;
                    FOLV.PrimarySortOrder  = SortOrder.None;
                }
                else
                {
                    FOLV.PrimarySortColumn = FOLV.AllColumns[olvState.SortColumn]; // FOLV.AllColumns(olvState.SortColumn)
                    FOLV.PrimarySortOrder  = olvState.LastSortOrder;
                }

                for (int i = 0; i <= olvState.NumberOfColumns - 1; i++)
                {
                    OLVColumn column = FOLV.AllColumns[i]; // FOLV.AllColumns(i)
                    column.Width            = System.Convert.ToInt32(olvState.ColumnWidths[i]);
                    column.IsVisible        = System.Convert.ToBoolean(olvState.ColumnIsVisible[i]);
                    column.LastDisplayIndex = System.Convert.ToInt32(olvState.ColumnDisplayIndicies[i]);
                }

                // ReSharper disable RedundantCheckBeforeAssignment
                if (olvState.IsShowingGroups != FOLV.ShowGroups)
                {
                    // ReSharper restore RedundantCheckBeforeAssignment
                    FOLV.ShowGroups = olvState.IsShowingGroups;
                }

                if (FOLV.View == olvState.CurrentView)
                {
                    FOLV.RebuildColumns();
                }
                else
                {
                    FOLV.View = olvState.CurrentView;
                }

                //tell other functions not to resize columns unless forced
                FOLV.Tag = "resizedcols";

                Ret = true;
            }
            catch (Exception ex)
            {
                Log("Error: " + ex.Msg());
            }

            return(Ret);
        }
Example #3
0
 private void GenerateColumns(FastObjectListView olv, List <OLVColumn> Cols)
 {
     olv.AllColumns.Clear();
     olv.AllColumns.AddRange(Cols);
     olv.RebuildColumns();
 }