void Add(ModelParameterGroupClass aGroup)
        {
            // Create new node
            ParmTreeNode Temp = new ParmTreeNode(aGroup, FPM);

            Nodes.Add(Temp);
        }
        void Add(int ParamCode)
        {
            // Create new node
            ParmTreeNode Temp = new ParmTreeNode(ParamCode, FPM);

            Nodes.Add(Temp);
        }
        //-------------------------------------------------------------------------------------
        internal ParmTreeNode _FindFieldname(TreeNodeCollection theNodes, string Fieldname)
        {
            ParmTreeNode temp = null;

            foreach (TreeNode node in theNodes)
            {
                if ((node as ParmTreeNode).isParamItemNode)
                {
                    if ((node as ParmTreeNode).ParmItem.Fieldname.CompareTo(Fieldname) == 0)
                    {
                        temp = (node as ParmTreeNode);
                        break;
                    }
                }
                if (node.Nodes.Count > 0)
                {
                    temp = _FindFieldname(node.Nodes, Fieldname);
                    if (temp != null)
                    {
                        break;
                    }
                }
            }

            return(temp);
        }
        internal void BuildTree()
        {
            ModelParameterGroupClass AllParmsGroup = new ModelParameterGroupClass("All Parameters");
            ParmTreeNode             AllParms      = new ParmTreeNode(AllParmsGroup, FParamManager);

            foreach (ModelParamItem MPI in FParamItems)
            {
                // get groups
                if (MPI.TopicsGroup.Count > 0)
                {
                    foreach (ModelParameterGroupClass MPG in MPI.TopicsGroup)
                    {
                        if (FAllGroups.Find(delegate(ModelParameterGroupClass item) {
                            return(item.ID == MPG.ID);
                        }) == null)
                        {
                            FAllGroups.Add(MPG);
                            ParmTreeNode temp = new ParmTreeNode(MPG, FParamManager);
                            TheParmNodes.Add(temp);
                        }
                    }
                }

                AllParms.Nodes.Add(new ParmTreeNode(MPI, FParamManager));
            }

            foreach (ParmTreeNode Node in TheParmNodes)
            {
                treeViewParameters.Nodes.Add(Node);
            }

            treeViewParameters.Nodes.Add(AllParms);
        }
        //-------------------------------------------------------------------------------------
        public ParmTreeNode FindFieldname(string Fieldname)
        {
            ParmTreeNode temp = null;

            temp = _FindFieldname(treeViewParameters.Nodes, Fieldname);
            return(temp);
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Executes the parm item select action. </summary>
        ///
        /// <param name="Node"> The node. </param>
        ///-------------------------------------------------------------------------------------------------

        protected virtual void OnParmItemSelect(ParmTreeNode Node)
        {
            if (Node != null)
            {
                if (ParmItemSelect != null)
                {
                    ParmItemSelect(this, Node);
                }
            }
        }
        // Invoke the ParmItemCheck

        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Executes the parm item check action. </summary>
        ///
        /// <param name="Node"> The node. </param>
        ///-------------------------------------------------------------------------------------------------

        protected virtual void OnParmItemCheck(ParmTreeNode Node)
        {
            //public delegate void ParmItemCheckEventHandler(object sender, ParmTreeNode Node);
            //  ItemCheckEventArgs e = new ItemCheckEventArgs();

            if (Node != null)
            {
                ParmItemCheck?.Invoke(this, Node);
            }
        }
 //-------------------------------------------------------------------------------------
 public void SetFieldsActive(List <string> theFields)
 {
     foreach (string fldstr in theFields)
     {
         ParmTreeNode PTN = FindFieldname(fldstr);
         if (PTN != null)
         {
             PTN.Enabled = true;;
         }
     }
 }
 //------------------------------------------------------------
 public static int CompareBasedOnField(ParmTreeNode Node1, ParmTreeNode Node2)
 {
     // OK, Groupnames are never sorted, always equal
     if ((Node1.isGroupNode) || (Node2.isGroupNode))
     {
         return(0);
     }
     else
     {
         return(Node1.ParmItem.Fieldname.CompareTo(Node2.ParmItem.Fieldname));
     }
 }
        //-----------------------------------------------------------------------------
        internal void SwapParmNodes(TreeNodeCollection theNodes, int index1, int index2)
        {
            ParmTreeNode temp1 = (theNodes[index1] as ParmTreeNode);
            ParmTreeNode temp2 = (theNodes[index2] as ParmTreeNode);

            theNodes.Remove(temp1);
            theNodes.Remove(temp2);
            theNodes.Insert(index1, temp2);
            theNodes.Insert(index2, temp1);

            //theNodes[index1] = theNodes[index2];
            //theNodes[index2] = temp;
        }
        //-----------------------------------------------------------------------------
        internal void _SortNodes(TreeNodeCollection Nodes, eSortParmItem SortBy)
        {
            int N = Nodes.Count;

            if (N > 0)
            {
                int index_of_min = 0;
                for (int iterator = 0; iterator < N - 1; iterator++)
                {
                    index_of_min = iterator;
                    for (int index = iterator + 1; index < N; index++)
                    {
                        int test = 0;
                        if (SortBy == eSortParmItem.spiFieldname)
                        {
                            test = ParmTreeNode.CompareBasedOnField((Nodes[index] as ParmTreeNode), (Nodes[index_of_min] as ParmTreeNode));
                        }
                        else
                        {
                            test = ParmTreeNode.CompareBasedOnLabel((Nodes[index] as ParmTreeNode), (Nodes[index_of_min] as ParmTreeNode));
                        }
                        if (test < 0)
                        {
                            index_of_min = index;
                        }
                    }
                    if (iterator != index_of_min)
                    {
                        SwapParmNodes(Nodes, iterator, index_of_min);
                    }
                }
            }

            foreach (TreeNode node in Nodes)
            {
                if (node.Nodes.Count > 0)
                {
                    _SortNodes(node.Nodes, SortBy);
                }
            }
        }