public override void BSkyBaseButtonCtrl_Click(object sender, RoutedEventArgs e)
        {
            double maxnoofvars     = 0;
            int    noSelectedItems = 0;
            int    i = 0;

            System.Windows.Forms.DialogResult diagResult;
            string             varList = "";
            string             message = "";
            DataSourceVariable o;

            //Aaron 09/07/2013
            //I had to use a list object as I could not create a variable size array object
            List <object> validVars   = new List <object>();
            List <object> invalidVars = new List <object>();

            //Added by Aaron 12/24/2013
            //You have the ability to move items to a textbox. When moving items to a textbox you don't have to check for filters
            //All we do is append the items selected separated by + into the textbox
            //We always copy the selected items to the textbox, items are never moved
            //We don't have to worry about tag

            //Destination is a BSkytargetlist
            noSelectedItems = vInputList.SelectedItems.Count;
            string newvar = "";

            //Checking whether variables moved are allowed by the destination filter
            //validVars meet filter requirements
            //invalidVars don't meet filter requirements


            if (vTargetList != null)
            {
                if (noSelectedItems == 0)
                {
                    diagResult = System.Windows.Forms.MessageBox.Show("You need to select a variable from the source variable list before clicking the move button", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    return;
                }


                if (vTargetList.GetType().Name == "SingleItemList" && noSelectedItems > 1)
                {
                    diagResult = System.Windows.Forms.MessageBox.Show("You cannot move more than 1 variable into a grouping variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    return;
                }

                if (noSelectedItems > 1)
                {
                    diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable at a time to specify polynomial critera", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    return;
                }

                //Added 10/19/2013
                //Added the code below to support listboxes that only allow a pre-specified number of items or less
                //I add the number of preexisting items to the number of selected items and if it is greater than limit, I show an error

                if (vTargetList.maxNoOfVariables != string.Empty && vTargetList.maxNoOfVariables != null)
                {
                    try
                    {
                        maxnoofvars = Convert.ToDouble(vTargetList.maxNoOfVariables);
                        //Console.WriteLine("Converted '{0}' to {1}.", vTargetList.maxNoOfVariables, maxnoofvars);

                        // diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the destination variable list" , "Message", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    }
                    catch (FormatException)
                    {
                        diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the target variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    }
                    catch (OverflowException)
                    {
                        diagResult = System.Windows.Forms.MessageBox.Show("An invalid value has been entered for the maximum number of variables in the target variable list", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    }
                    if (maxnoofvars < (noSelectedItems + vTargetList.ItemsCount))
                    {
                        //e.Effects = DragDropEffects.None;
                        //e.Handled = true;
                        message    = "The target variable list cannot have more than " + vTargetList.maxNoOfVariables + " variable(s). Please reduce your selection or remove variables from the target list";
                        diagResult = System.Windows.Forms.MessageBox.Show(message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                        return;
                    }
                }


                object objspin = GetResource(TextBoxForpolynomialOrder);
                if (objspin == null || (!(objspin is BSkySpinnerCtrl)))
                {
                    MessageBox.Show("Unable to associate this polynomial control with a Spinner control on the same canvas, you must specify a spinner control");
                    return;
                }
                //If there are valid variables then move them
                BSkySpinnerCtrl spin = objspin as BSkySpinnerCtrl;
                // IList<DataSourceVariable> Items = new List<DataSourceVariable>();
                List <DataSourceVariable> Items    = new List <DataSourceVariable>();
                DataSourceVariable        inputVar = vInputList.SelectedItems[0] as DataSourceVariable;
                int  polynomialdegree         = Int32.Parse(spin.text.Text);
                int  startingpolynomialdegree = 1;
                bool itemIsInTarget           = false;
                //Lets say the degree of the polynomial is 4, so engine^4, then we need to add
                //I(engine^4) and I(engine^3) and I(engine^2) and I(engine^1)
                //Now if you add I(engine^5), only I(engine^5) should be added as I(engine^4) are already there
                while (polynomialdegree != 0)
                {
                    newvar = "I(" + inputVar.Name + "^" + startingpolynomialdegree + ")";
                    //Preferred way
                    DataSourceVariable ds = new DataSourceVariable();
                    ds.XName     = newvar;
                    ds.Name      = newvar;
                    ds.RName     = newvar;
                    ds.Measure   = inputVar.Measure;
                    ds.DataType  = inputVar.DataType;
                    ds.Width     = inputVar.Width;
                    ds.Decimals  = inputVar.Decimals;
                    ds.Label     = inputVar.Label;
                    ds.Alignment = inputVar.Alignment;
                    ds.ImgURL    = inputVar.ImgURL;

                    if (vTargetList.ItemsCount == 0)
                    {
                        Items.Add(ds);
                    }
                    else
                    {
                        foreach (DataSourceVariable obj in vTargetList.Items)
                        {
                            if (obj.RName == ds.RName)
                            {
                                itemIsInTarget = true;
                            }
                        }
                        if (!itemIsInTarget)
                        {
                            Items.Add(ds);
                        }
                    }

                    polynomialdegree         = polynomialdegree - 1;
                    startingpolynomialdegree = startingpolynomialdegree + 1;
                    itemIsInTarget           = false;
                }



                //vTargetList.SetSelectedItems(arr1);
                //Added by Aaron on 12/24/2012 to get the items moved scrolled into view
                //Added by Aaron on 12/24/2012. Value is 0 as you want to scroll to the top of the selected items
                if (Items.Count != 0)
                {
                    vTargetList.AddItems(Items);
                    vTargetList.ScrollIntoView(Items[0]);
                }
                // Added by Aaron 06/09/2020
                // We will never remove the variable being moved from the source variable list
                // if (vInputList.MoveVariables)
                ////The compiler is not allowing me to use vInputList.Items.Remove() so I have to use ItemsSource
                //{
                //    ListCollectionView lcw = vInputList.ItemsSource as ListCollectionView;
                //    foreach (object obj in validVars) lcw.Remove(obj);
                // }
                vTargetList.Focus();
            }
            //Added by Aaron 07/22/2015
            //This is a valid point
            //else
            //{


            //    vTargetList.AddItems(validVars);

            //    //The code below unselects everything
            //    vTargetList.UnselectAll();
            //    //The code below selects all the items that are moved
            //    vTargetList.SetSelectedItems(validVars);
            //    //Added by Aaron on 12/24/2012 to get the items moved scrolled into view
            //    //Added by Aaron on 12/24/2012. Value is 0 as you want to scroll to the top of the selected items
            //    vTargetList.ScrollIntoView(validVars[0]);
            //}
            if (vInputList.MoveVariables)
            //The compiler is not allowing me to use vInputList.Items.Remove() so I have to use ItemsSource
            {
                ListCollectionView lcw = vInputList.ItemsSource as ListCollectionView;
                foreach (object obj in validVars)
                {
                    lcw.Remove(obj);
                }
            }
            if (vTargetList != null)
            {
                vTargetList.Focus();
            }

            //Added by Aaron 08/13/2014
            //This is for the case that I am moving a variable year to a target list that already contains year
            //validvars.count is 0 as I have already detercted its in the target variable. I now want to high light it in the targetvariable
            if (validVars.Count == 0)
            {
                List <object> firstitem = new List <object>();
                firstitem.Add(vInputList.SelectedItems[0]);

                if (vTargetList != null)
                {
                    if (vTargetList.Items.Contains(vInputList.SelectedItems[0]))
                    {
                        vTargetList.SetSelectedItems(firstitem);
                        vTargetList.Focus();
                    }
                }
            }
            //If there are variables that don't meet filter criteria, inform the user
            if (invalidVars.Count > 0)
            {
                string cantMove = string.Join(",", invalidVars.ToArray());
                System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("The variable(s) \"" + cantMove + "\" cannot be moved, the destination variable list does not allow variables of that type", "Save Changes", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
            }
        }
        public FrameworkElement CreateControl(string objtype)
        {
            FrameworkElement b = null;

            switch (objtype)
            {
            case "SourceListBox":
                //When invoked from the dialog creator, renderVars is set to true
                //   CommonFunctions cf = new CommonFunctions();
                b = new BSkySourceList(true, true);
                BSkySourceList c = b as BSkySourceList;
                //  cf.DisplayNameGridProperty(c, "Type", "The source variable list displays all the variables in the active dataset.");
                //  cf.DisplayNameGridProperty(c, "CanExecute", "Default value is True. This property controls whether the OK button on the dialog is enabled or disabled.If CanExecute =true for all controls on the dialog and contained sub-dialogs, the OK button is enabled, if CanExecute =false for any one control on the dialog or contained sub-dialogs, the OK button is disabled.");
                //cf.DisplayNameGridProperty(c, "SelectionChangeBehaviour", "Default is empty(no rule). Use this optional property to define rules that trigger property changes in this or other controls, based on the change in state of this variable list control.");

                //     [Description("Default is empty(no rule). Use this optional property to define rules that trigger property changes in this or other controls, based on the change in state of this checkbox control. For example, if a user checks the checkbox, enable a textbox control to capture additional parameters. To define a rule, click in the property and click the elipses button.")]
                b.Width  = 135;
                b.Height = 240;
                break;

            case "TargetListBox":
                b = new BSkyTargetList(false, true);
                BSkyTargetList c1 = b as BSkyTargetList;
                //CommonFunctions cf1 = new CommonFunctions();
                //cf1.DisplayNameGridProperty(c1, "Type", "The target variable list contains the variables you want to analyze. Drag and drop the variables you want to analyze from the source variable list to one or more target variable lists.");

                //cf1.DisplayNameGridProperty(c1, "CanExecute", "Default value is True. This property controls whether the OK button on the dialog is enabled or disabled. If CanExecute =true for all controls on the dialog and contained sub-dialogs, the OK button is enabled, if CanExecute =false for any one control on the dialog or contained sub-dialogs, the OK button is disabled. For example, if a user adds a variable to this variable list, set the canexecute property to 'true', which enables the OK button on the dialog (remember to set another rule to set canexecute to false when All items are removed from this variable list and the value of the itemscount property is 0). This ensures that the dialog cannot be executed unless one or more items are dragged and dropped into this variable list control. To define a rule, click in the property and then click the elipses button.");

                //cf1.DisplayNameGridProperty(c1, "SelectionChangeBehaviour", "Default is empty(no rule). Use this optional property to define rules that trigger property changes in this or other controls, based on the change in state of this variable list control.For example, if a user adds a variable to this variable list, set the canexecute property to 'true', which enables the OK button on the dialog (remember to set another rule to set canexecute to false when All items are removed from this variable list and the value of the itemscount property is 0). This ensures that the dialog cannot be executed unless one or more items are dragged and dropped into this variable list control. To define a rule, click in the property and then click the elipses button.");
                b.Width  = 135;
                b.Height = 240;
                break;

            case "Button":
                b        = new BSkyButton();
                b.Width  = 100;
                b.Height = 30;
                break;

            case "textbox":
                b        = new BSkyTextBox();
                b.Width  = 135;
                b.Height = 30;
                break;

            case "GrpBox":
                b        = new BSkyGroupBox();
                b.Width  = 150;
                b.Height = 100;
                break;

            case "ChkBox":
                b        = new BSkyCheckBox();
                b.Width  = 75;
                b.Height = 20;
                break;

            case "RdBtn":
                b        = new BSkyRadioButton();
                b.Width  = 75;
                b.Height = 20;
                break;

            case "EditCombo":
                b        = new BSkyEditableComboBox();
                b.Width  = 100;
                b.Height = 25;
                break;

            case "NonEditCombo":
                b        = new BSkyNonEditableComboBox();
                b.Width  = 100;
                b.Height = 25;
                break;

            case "Label":
                b        = new BSkyLabel();
                b.Width  = 50;
                b.Height = 25;
                break;

            case "LabelForRequiredFld":
                b        = new BSkyLabelReqdField();
                b.Width  = 15;
                b.Height = 25;
                break;

            case "MultiLabel":
                b        = new BSkyMultiLineLabel();
                b.Width  = 100;
                b.Height = 25;
                break;

            case "Canvas":
                b = new BSkyCanvas();
                BSkyCanvas.dialogMode = true;
                b.Width  = 470;
                b.Height = 300;
                //    b.Width = 0;
                //  b.Height = 0;
                break;

            case "MoveButton":
                // b = new BSkyVariableMoveButton(true);
                b        = new BSkyVariableMoveButton();
                b.Width  = 35;
                b.Height = 35;
                break;

            case "RadioGroup":
                b        = new BSkyRadioGroup();
                b.Width  = 100;
                b.Height = 100;
                break;

            // Added by Aaron 03/31
            case "Browse":
                b        = new BSkyBrowse();
                b.Width  = 100;
                b.Height = 30;
                break;

            case "GroupingVariable":
                b       = new BSkyGroupingVariable();
                b.Width = 135;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                b.Height = 30;
                break;

            case "gridForSymbols":
                // b = new BSkyScrollTextBox();
                b = new BSkygridForSymbols();
                //b.Width = 135;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "GridforCompute":
                // b = new BSkyScrollTextBox();
                b        = new BSkygridForCompute();
                b.Width  = 300;
                b.Height = 300;
                //b.Width = 135;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;


            case "ListBox":
                // b = new BSkyScrollTextBox();
                b        = new BSkyListBox();
                b.Width  = 135;
                b.Height = 120;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "SourceDatasetList":
                b        = new BSkyListBoxwBorderForDatasets(true, true);
                b.Width  = 135;
                b.Height = 120;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "DestinationDatasetList":
                b        = new BSkyListBoxwBorderForDatasets(false, true);
                b.Width  = 135;
                b.Height = 120;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;


            case "MasterListBox":
                // b = new BSkyScrollTextBox();
                b        = new BSkyMasterListBox();
                b.Width  = 135;
                b.Height = 120;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "AggregateCtrl":
                b        = new BSkyAggregateCtrl();
                b.Width  = 235;
                b.Height = 335;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "SortCtrl":
                b        = new BSkySortCtrl();
                b.Width  = 280;
                b.Height = 202;
                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "SliderCtrl":
                b = new BSkySlider();
                // BSkySlider b1 = b as BSkySlider;
                // b1.Ticks = null;
                b.Width  = 135;
                b.Height = 40;
                //  b1.TickFrequency = 2;
                //  b1.Maximum = 10;
                //  b1.Minimum = 0;
                // b1.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.Both;
                //TickFrequency = 2;
                // b1.Ticks = null;

                //DoubleCollection tickMarks = new DoubleCollection();
                //tickMarks.Add(0.5);
                //tickMarks.Add(1.5);
                //tickMarks.Add(2.5);
                //tickMarks.Add(3.5);
                //tickMarks.Add(4.5);
                //tickMarks.Add(5.5);
                //tickMarks.Add(6.5);
                //tickMarks.Add(7.5);
                //tickMarks.Add(8.5);
                //tickMarks.Add(9.5);
                //b1.Ticks = tickMarks;
                //  b1.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight;

                // BSkyGroupingVariable bc = b as BSkyGroupingVariable;
                // bc.oneItemList.Width = 100;
                // bc.Height = 50;
                //b.Height = 40;
                break;

            case "AdvancedSliderCtrl":
                b = new BSkyAdvancedSlider();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 135;
                b.Height = 45;
                break;

            case "BSkySpinnerCtrl":
                b = new BSkySpinnerCtrl();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 83;
                b.Height = 22;
                break;


            case "BSkyInteractionControl":
                b = new BSkyInteractionCtrl();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 35;
                b.Height = 35;
                break;


            case "BSkyPolynomialCtrl":
                b = new BSkyPolynomialCtrl();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 35;
                b.Height = 35;
                break;

            case "BSkyDeleteButton":
                b = new BSkyDeleteButton();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 35;
                b.Height = 35;
                break;

            case "BSkyNWayInteraction":
                b = new BSkyNWayInteraction();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 35;
                b.Height = 35;
                break;

            case "BSkyAddFixedEffects":
                b = new BSkyAddFixedEffects();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 35;
                b.Height = 35;
                break;

            case "BSkyNestingCtrl":
                b = new BSkyNestingCtrl();
                // BSkyAdvancedSlider b1 = b as BSkyAdvancedSlider;
                // b1.Ticks = null;
                b.Width  = 35;
                b.Height = 35;
                break;
            }

            //b.Name = GetName(objtype);
            return(b);
        }