/// <summary>
        /// Removes all items from list collection view.
        /// </summary>
        /// <param name="theViewToUpdate">The view to update.</param>
        public static void RemoveAllItemsFromListCollectionView(this ListCollectionView theViewToUpdate)
        {
            //remove new item place holder

            if (theViewToUpdate.NewItemPlaceholderPosition != NewItemPlaceholderPosition.None)
            {
                theViewToUpdate.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None;
            }

            if (theViewToUpdate.Count > 0)
            {
                int index = 0;

                var theItem = theViewToUpdate.GetItemAt(index);

                while (theItem != null)
                {
                    theViewToUpdate.Remove(theItem);

                    if (theViewToUpdate.Count > 0)
                    {
                        theItem = theViewToUpdate.GetItemAt(index);
                    }

                    else
                    {
                        theItem = null;
                    }
                }

                theViewToUpdate.Refresh();
            }
        }
Ejemplo n.º 2
0
 void DeleteCommandExecute(Object parameter)
 {
     _status = null;
     if (MessageBox.Show("确定删除该记录", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
     {
         DBInstance.DeleteRecord(SelectedID);
         MainWork           mw  = parameter as MainWork;
         ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(mw.lvCredentialInfo.ItemsSource);
         lcv.Remove(SelectedCredential);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Remove the specified group from the collection.
 /// </summary>
 /// <param name="group">The group to remove</param>
 private void RemoveGroup(Group group)
 {
     if (!_groups.Remove(group))
     {
         throw new ArgumentException("Group " + group.Name + " does not exist");
     }
     //Remove the group's categories
     foreach (Category category in group.Categories)
     {
         _categories.Remove(category);
     }
 }
        //Added by Aaron 02/24/2013
        //The code below is modified to not fire the drag and drop when I am dragging the scroll bar
        //If I am dragging and dropping the scroll bar and I accidently mouse over an item in the variable  list,
        //the problem was the drag and drop was initiated
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (renderVars)
            {
                return;
            }
            BSkyCanvas.sourceDrag = (DragDropList)this;
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                //Added by Aaron 02/24/2013
                //The function below checks whether the origin of the drag and drop was the scroll bar
                if (isscrollbarclickedon(e) == true)
                {
                    return;
                }
                object data = GetDataFromListBox(this, e.GetPosition(this)) as object;

                //02/23/2013 Aaron
                //Code below could be used for multi drag and drop
                //object data = ((ListBox)(FrameworkElement)this).SelectedItem;

                //If the drag and drop was initiated on the scroll bar,data =null
                if (data != null)
                {
                    DragDropEffects    effs;
                    ListCollectionView lst = this.ItemsSource as ListCollectionView;

                    //We have the option to move or copy variables from a listbox
                    //This is governed by the movevariables property
                    if (this.MoveVariables)
                    {
                        effs = DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move);

                        //
                        if (effs == DragDropEffects.Copy)
                        {
                            if (lst.IsAddingNew)
                            {
                                lst.CommitNew();
                            }
                            lst.Remove(data);
                        }
                    }
                    else
                    {
                        effs = DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void DeletePerson(object o)
        {
            ListCollectionView lcv = GetIt <ListCollectionView>(PROP_NAME);

            PersonVM selectedPerson = (PersonVM)lcv.CurrentItem;

            if (selectedPerson == null)
            {
                return;
            }

            lcv.Remove(selectedPerson);
            ShowMessage("Selected Person has been removed!");
        }
Ejemplo n.º 6
0
        private void DeleteNewBtn_Click(object sender, RoutedEventArgs e)
        {
            if (lcv.CurrentItem == null)
            {
                return;
            }

            EmployeeInfo employeeInfo = lcv.CurrentItem as EmployeeInfo;

            if (lcv.CanRemove)
            {
                lcv.Remove(employeeInfo);
            }
        }
Ejemplo n.º 7
0
        protected virtual void RemoveCommand(object sender, RoutedEventArgs e)
        {
            ListCollectionView lc = ListCollectionView;

            //if (lc.IsAddingNew)
            //    lc.CancelNew();
            //else
            //{

            lc.CommitEdit();
            foreach (var item in this.SelectedItems.ToArray())
            {
                lc.Remove(item);
            }
        }
        public void RemoveSelectedItems()
        {
            ListCollectionView lcw = this.ItemsSource as ListCollectionView;

            object[] arr = new object[this.SelectedItems.Count];
            int      i   = 0;

            foreach (object obj in this.SelectedItems)
            {
                arr[i++] = obj;
            }

            foreach (object obj in arr)
            {
                lcw.Remove(obj);
            }
        }
Ejemplo n.º 9
0
        protected DictionaryViewModel(IServiceLocator serviceLocator, IMessageService messageService)
        {
            _ServiceLocator = serviceLocator;
            _MessageService = messageService;

            Entities = new ListCollectionView(_Entities);
            Entities.CurrentChanged += (sender, args) => DeleteCommand.RaiseCanExecuteChanged();

            AddCommand = new DelegateCommand(() =>
            {
                var viewModel = CreateNewViewModel(CreateNewModel());
                var error     = viewModel.Error;
                if (error == null)
                {
                    viewModel.SaveToDatabase();
                    _Entities.Add(viewModel);
                    ClearProperties();
                }
                else
                {
                    _MessageService.ShowMessage(error, "Ошибка", image: MessageBoxImage.Error);
                }
                AddCommand.RaiseCanExecuteChanged();
            }, CanAdd);

            DeleteCommand = new DelegateCommand(() =>
            {
                if (Entities.CurrentItem != null)
                {
                    var current = Entities.CurrentItem;
                    Entities.Remove(current);
                }
                else
                {
                    _MessageService.ShowMessage("Выберите удаляемый элемент", "Ошибка", image: MessageBoxImage.Error);
                }
                DeleteCommand.RaiseCanExecuteChanged();
            }, CanDelete);
        }
        /// <summary>
        /// Removes the items from list collection view.
        /// </summary>
        /// <param name="theViewToUpdate">The view to update.</param>
        /// <param name="theRemoveList">The remove list.</param>
        public static void RemoveItemsFromListCollectionView(this ListCollectionView theViewToUpdate, List <object> theRemoveList)
        {
            //Finish all other state before remove item

            if (theViewToUpdate.IsAddingNew)
            {
                theViewToUpdate.CommitNew();
            }

            if (theViewToUpdate.IsEditingItem)
            {
                theViewToUpdate.CommitEdit();
            }

            //Remove items

            foreach (var item in theRemoveList)
            {
                theViewToUpdate.Remove(item);
            }

            //theViewToUpdate.Refresh();
        }
        public static void Clear(this ListCollectionView view)
        {
            if (view.IsAddingNew)
            {
                view.CommitNew();
            }
            if (view.IsEditingItem)
            {
                view.CommitEdit();
            }

            if (view.NewItemPlaceholderPosition != NewItemPlaceholderPosition.None)
            {
                view.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None;
            }

            while (view.Count > 0)
            {
                var theItem = view.GetItemAt(0);
                view.Remove(theItem);
            }

            view.Refresh();
        }
Ejemplo n.º 12
0
        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 nesting control", "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 from the source variable list to specify a nested effect. You have more than 1 variable selected in the source variable list", "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.SelectedItems.Count > 1)
                {
                    diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable from the source variable list and 1 variable from the target variable to specify a nested effect. You have more than 1 variable selected in the target variable list.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    return;
                }

                if (vTargetList.SelectedItems.Count == 0)
                {
                    diagResult = System.Windows.Forms.MessageBox.Show("You need to select 1 variable from the source variable list and 1 variable from the target variable to specify a nested effect. The target variable list is empty. You need to add a variable to the target variable list and then create a nested effect.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                    return;
                }

                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;
                    }
                }



                DataSourceVariable inputVar = vInputList.SelectedItems[0] as DataSourceVariable;



                // vTargetList.ItemsSource
                //vTargetList.ItemsSource

                //Preferred
                ListCollectionView temp;
                temp = vTargetList.ItemsSource as ListCollectionView;
                int selectedIndex = 0;
                selectedIndex = vTargetList.SelectedIndex;
                int count = vTargetList.ItemsCount;

                for (i = 0; i < count; i++)
                {
                    validVars.Add(vTargetList.Items[i]);
                }

                ListCollectionView lcw = vTargetList.ItemsSource as ListCollectionView;
                foreach (object obj in validVars)
                {
                    lcw.Remove(obj);
                }

                DataSourceVariable ds = validVars[selectedIndex] as DataSourceVariable;

                // DataSourceVariable ds = preview[index] as DataSourceVariable;

                //DataSourceVariable ds = new DataSourceVariable();
                newvar       = inputVar.Name + "(" + ds.Name + ")";
                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;
                validVars[selectedIndex] = ds;

                // vTargetList.ItemsSource = preview;
                // validVars.Add(ds as object);
                // vTargetList.AddItems(validVars);

                // vInputList.SelectedItems[i]
                //    validVars.Add(vInputList.SelectedItems[1]);


                vTargetList.AddItems(validVars);
                //The code below unselects everything
                //      vTargetList.UnselectAll();
                //The code below selects all the items that are moved
                //    vTargetList.SetSelectedItems(validVars);
                //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
                //  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);
                //}
                vTargetList.ScrollIntoView(validVars[selectedIndex]);
                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 virtual void ListBox_Drop(object sender, DragEventArgs e)
        {
            string[] formats = e.Data.GetFormats();

            //BSkyCanvas.destDrag = (ListBox)sender;
            //The code below disables drag and drop on the source list, added June 16th


            int destindex, i, j, sourceindex, noofitems;


            //object[] newlist =null;

            //Aaron Modified 11/04
            if (AutoVar == false && this == BSkyCanvas.sourceDrag)
            {
                e.Effects = DragDropEffects.None;
                return;
            }


            if (formats.Length > 0)
            {
                object             sourcedata = e.Data.GetData(formats[0]) as object;
                ListCollectionView list       = this.ItemsSource as ListCollectionView;

                if (sourcedata != null)
                {
                    //Soure and destination are different
                    if (this != BSkyCanvas.sourceDrag)
                    {
                        //AARON ADD YOUR CODE HERE
                        //Added by Aaron 10/02/2015
                        //Dragdroplist for summarize is used in 2 places
                        //The aggregatre control and the sort control
                        //In the aggregate control, I need to support copying variables as I need                                    //to support mean(var1), median(var1)...
                        //To support the above use case, I create a new data variable object
                        //The new object when moved from the target to the source can create a
                        //duplicate variable
                        //The line below, prevents the addition of the new variable and gets triggered only on the sort
                        //SO BASICALLY IF I AM MOVING ITEMS TO THE SOURCE VARIABLE FROM THE AGGREGATE CONTROL NO NEW VARIABLES ARE EVER CREATED IN THE SOURCE VARIABLE
                        //NEW VARIABLES ARE CREATED ONLY WITH THE SORT CONTROL

                        if (this.MoveVariables == true)
                        {
                            if (list.IndexOf(sourcedata) < 0)
                            {
                                list.AddNewItem(sourcedata);
                                list.CommitNew();

                                //this.SelectedItem = d;
                                //e.Effects =  DragDropEffects.All;
                                this.ScrollIntoView(sourcedata);//AutoScroll
                            }
                        }

                        //Aaron 09/11/2013 Commented 2 lines below
                        //else
                        //   e.Effects =  DragDropEffects.None;
                        //this.UnselectAll();
                        //02/24 Aaron
                        //This is to signify that since the source and destination are different, we have finished the copy.
                        //We will go back to the initiation of the drag and drop to see if the source needs to be removed or kept
                        // in the source listbox. This will be determined by the value of movevariables property
                        e.Effects         = DragDropEffects.Copy;
                        this.SelectedItem = sourcedata;
                        Focus();
                    }

                    //The source and the destination are the same i.e. the target variable
                    else


                    {
                        object destdata = GetDataFromListBox(this, e.GetPosition(this)) as object;
                        if (destdata == sourcedata)
                        {
                            return;
                        }
                        destindex = list.IndexOf(destdata);
                        noofitems = list.Count;
                        object[] newlist = new object[noofitems];
                        sourceindex = list.IndexOf(sourcedata);
                        if (destindex != sourceindex)
                        {
                            //This is the case of move to the end

                            if (destindex == -1)
                            {
                                for (i = 0; i < noofitems; i++)
                                {
                                    if (i == sourceindex)
                                    {
                                        while (i <= (noofitems - 2))
                                        {
                                            newlist[i] = list.GetItemAt(i + 1);
                                            i          = i + 1;
                                        }
                                        newlist[i] = list.GetItemAt(sourceindex);
                                        i          = i + 1;
                                    }

                                    else
                                    {
                                        newlist[i] = list.GetItemAt(i);
                                    }
                                }
                            } //End of move to the end

                            else
                            {
                                if (destindex < sourceindex)
                                {
                                    for (i = 0; i < noofitems; i++)
                                    {
                                        j = i;


                                        if (i == destindex)
                                        {
                                            newlist[i] = list.GetItemAt(sourceindex);
                                            i          = i + 1;


                                            while (j < noofitems)
                                            {
                                                if (j != sourceindex)
                                                {
                                                    newlist[i] = list.GetItemAt(j);
                                                    i          = i + 1;
                                                }
                                                j = j + 1;
                                            }
                                        }

                                        else
                                        {
                                            newlist[i] = list.GetItemAt(i);
                                        }
                                    }
                                } ////End when sourceindex > destindex

                                else if (sourceindex < destindex) //I have tested this
                                {
                                    for (i = 0; i < noofitems; i++)
                                    {
                                        j = i;


                                        if (i == sourceindex)
                                        {
                                            j = j + 1;


                                            while (i < noofitems)
                                            {
                                                if (i == destindex)
                                                {
                                                    newlist[i] = list.GetItemAt(sourceindex);
                                                    i          = i + 1;
                                                }


                                                else
                                                {
                                                    newlist[i] = list.GetItemAt(j);
                                                    j          = j + 1;
                                                    i          = i + 1;
                                                }
                                            }
                                        }


                                        else
                                        {
                                            newlist[i] = list.GetItemAt(i);
                                        }
                                    }

                                    //End of for loop
                                }  //end of destindex > sourceindex

                                //end of else if
                            }

                            //end of else


                            //End of the case move to end
                        }

                        //end of case destindex !=source index
                        if (list.IsAddingNew)
                        {
                            list.CommitNew();
                        }

                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(newlist[i]);
                        }

                        for (i = 0; i < noofitems; i++)
                        {
                            list.AddNewItem(newlist[i]);
                            list.CommitNew();
                            //this.ScrollIntoView(newlist[i]);//AutoScroll
                        }
                        list.Refresh();
                        this.SelectedItem = sourcedata;
                        //02/24 Aaron
                        //This is to signify that since the source and destination is the same, we have performed a move
                        e.Effects = DragDropEffects.Move;
                    }

                    //end of source and destination and the same (target listbox
                }

                //sourcedata |=null
            }

            //formats.length >0
        }
        public virtual void ListBox_Drop(object sender, DragEventArgs e)
        {
            string functionName;
            bool   doesAggOptionExist = false;

            string[] formats       = e.Data.GetFormats();
            int      firstpos      = 0;
            int      lastpos       = 0;
            bool     filterResults = false;

            //BSkyCanvas.destDrag = (ListBox)sender;
            //The code below disables drag and drop on the source list, added June 16th


            int destindex, i, j, sourceindex, noofitems;


            //object[] newlist =null;

            //Aaron Modified 11/04
            if (AutoVar == false && this == BSkyCanvas.sourceDrag)
            {
                e.Effects = DragDropEffects.None;
                return;
            }


            if (formats.Length > 0)
            {
                object             sourcedata = e.Data.GetData(formats[0]) as object;
                ListCollectionView list       = this.ItemsSource as ListCollectionView;

                if (sourcedata != null)
                {
                    //Soure and destination are different
                    if (this != BSkyCanvas.sourceDrag)
                    {
                        //Added by Aaron 07/22/2015
                        if (list.IndexOf(sourcedata) < 0)
                        {
                            //Added by Aaron 07/22/2015
                            //a dragdrop list class has a property summary control. This indicates that it is used
                            //in a summary control. If this is true, i have to prefix the variable name by the
                            //function name in the combo box
                            //if (this.summaryCtrl == true)
                            //{
                            functionName = getFunctionFromComboBox();
                            DataSourceVariable ds = sourcedata as DataSourceVariable;
                            if (functionName != "asc")
                            {
                                ds.XName = functionName + "(" + ds.RName + ")";
                            }
                            else
                            {
                                ds.XName = ds.RName;
                            }
                            //ds.XName = functionName + "(" + ds.RName + ")";
                            list.AddNewItem(ds);
                            list.CommitNew();
                            //}
                            //else
                            //{
                            //Added by Aaron 07/22/2015
                            //If I am moving the variable back from a drag drop that is associated with a summary control, I need to remove the sumarizing function
                            //if (BSkyCanvas.sourceDrag is DragDropListForSummarize)
                            //{
                            //    DataSourceVariable ds1 = sourcedata as DataSourceVariable;

                            //    firstpos = ds1.Name.IndexOf(@"(");
                            //    lastpos = ds1.Name.IndexOf(@")");
                            //    ds1.XName = ds1.XName.Substring(firstpos+1, (lastpos - (firstpos+1)));
                            //}

                            // list.AddNewItem(sourcedata);
                            // list.CommitNew();
                            //}
                            //this.SelectedItem = d;
                            //e.Effects =  DragDropEffects.All;
                            this.ScrollIntoView(sourcedata);//AutoScroll
                        }
                        else
                        {
                            //Check if the aggregate option is already present
                            functionName       = getFunctionFromComboBox();
                            doesAggOptionExist = checkIfAggregateOptionExists(this, sourcedata as DataSourceVariable, functionName);
                            DataSourceVariable ds = sourcedata as DataSourceVariable;
                            if (!doesAggOptionExist)
                            {
                                DataSourceVariable newds = new DataSourceVariable();
                                //31Jul2016 9:43AM :Anil: line will not work as we moved RNAME out of the Name property in DataSource:  newds.Name = ds.RName; //RName can support A.2 as col name
                                newds.RName     = ds.RName; //Anil: This fixes: 31Jul2016 9:43AM
                                newds.XName     = ds.XName;
                                newds.DataType  = ds.DataType;
                                newds.DataClass = ds.DataClass;
                                newds.Width     = ds.Width;
                                newds.Decimals  = ds.Decimals;
                                newds.Label     = ds.Label;
                                newds.Values    = ds.Values;
                                newds.Missing   = ds.Missing;
                                newds.MissType  = ds.MissType;
                                newds.Columns   = ds.Columns;
                                newds.Measure   = ds.Measure;
                                newds.ImgURL    = ds.ImgURL;
                                filterResults   = this.CheckForFilter(newds);
                                if (filterResults)
                                {
                                    if (functionName != "asc")
                                    {
                                        newds.XName = functionName + "(" + newds.RName + ")";
                                    }
                                    else
                                    {
                                        newds.XName = newds.RName;
                                    }

                                    //newds.XName = functionName + "(" + ds.RName + ")";
                                    list.AddNewItem(newds);
                                    list.CommitNew();

                                    this.ScrollIntoView(newds);//AutoScroll
                                }
                                // else
                                // {
                                //     invalidVars.Add(vInputList.SelectedItems[i]);
                                // }
                            }
                        }

                        //Aaron 09/11/2013 Commented 2 lines below
                        //else
                        //   e.Effects =  DragDropEffects.None;
                        //this.UnselectAll();
                        //02/24 Aaron
                        //This is to signify that since the source and destination are different, we have finished the copy.
                        //We will go back to the initiation of the drag and drop to see if the source needs to be removed or kept
                        // in the source listbox. This will be determined by the value of movevariables property
                        e.Effects         = DragDropEffects.Copy;
                        this.SelectedItem = sourcedata;
                        Focus();
                    }

                    //The source and the destination are the same i.e. the target variable
                    else


                    {
                        object destdata = GetDataFromListBox(this, e.GetPosition(this)) as object;
                        if (destdata == sourcedata)
                        {
                            return;
                        }
                        destindex = list.IndexOf(destdata);
                        noofitems = list.Count;
                        object[] newlist = new object[noofitems];
                        sourceindex = list.IndexOf(sourcedata);
                        if (destindex != sourceindex)
                        {
                            //This is the case of move to the end

                            if (destindex == -1)
                            {
                                for (i = 0; i < noofitems; i++)
                                {
                                    if (i == sourceindex)
                                    {
                                        while (i <= (noofitems - 2))
                                        {
                                            newlist[i] = list.GetItemAt(i + 1);
                                            i          = i + 1;
                                        }
                                        newlist[i] = list.GetItemAt(sourceindex);
                                        i          = i + 1;
                                    }

                                    else
                                    {
                                        newlist[i] = list.GetItemAt(i);
                                    }
                                }
                            } //End of move to the end

                            else
                            {
                                if (destindex < sourceindex)
                                {
                                    for (i = 0; i < noofitems; i++)
                                    {
                                        j = i;


                                        if (i == destindex)
                                        {
                                            newlist[i] = list.GetItemAt(sourceindex);
                                            i          = i + 1;


                                            while (j < noofitems)
                                            {
                                                if (j != sourceindex)
                                                {
                                                    newlist[i] = list.GetItemAt(j);
                                                    i          = i + 1;
                                                }
                                                j = j + 1;
                                            }
                                        }

                                        else
                                        {
                                            newlist[i] = list.GetItemAt(i);
                                        }
                                    }
                                } ////End when sourceindex > destindex

                                else if (sourceindex < destindex) //I have tested this
                                {
                                    for (i = 0; i < noofitems; i++)
                                    {
                                        j = i;


                                        if (i == sourceindex)
                                        {
                                            j = j + 1;


                                            while (i < noofitems)
                                            {
                                                if (i == destindex)
                                                {
                                                    newlist[i] = list.GetItemAt(sourceindex);
                                                    i          = i + 1;
                                                }


                                                else
                                                {
                                                    newlist[i] = list.GetItemAt(j);
                                                    j          = j + 1;
                                                    i          = i + 1;
                                                }
                                            }
                                        }


                                        else
                                        {
                                            newlist[i] = list.GetItemAt(i);
                                        }
                                    }

                                    //End of for loop
                                }  //end of destindex > sourceindex

                                //end of else if
                            }

                            //end of else


                            //End of the case move to end
                        }

                        //end of case destindex !=source index
                        if (list.IsAddingNew)
                        {
                            list.CommitNew();
                        }

                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(newlist[i]);
                        }

                        for (i = 0; i < noofitems; i++)
                        {
                            list.AddNewItem(newlist[i]);
                            list.CommitNew();
                            //this.ScrollIntoView(newlist[i]);//AutoScroll
                        }
                        list.Refresh();
                        this.SelectedItem = sourcedata;
                        //02/24 Aaron
                        //This is to signify that since the source and destination is the same, we have performed a move
                        e.Effects = DragDropEffects.Move;
                    }

                    //end of source and destination and the same (target listbox
                }

                //sourcedata |=null
            }

            //formats.length >0
        }
        public virtual void ListBox_Drop(object sender, DragEventArgs e)
        {
            string[] formats = e.Data.GetFormats();

            //BSkyCanvas.destDrag = (ListBox)sender;
            //The code below disables drag and drop on the source list, added June 16th


            int destindex, i, j, sourceindex, noofitems;


            //object[] newlist =null;

            //Aaron Modified 11/04
            if (AutoPopulate == true && this == BSkyCanvas.sourceDataset)
            {
                e.Effects = DragDropEffects.None;
                return;
            }


            if (formats.Length > 0)
            {
                object sourcedata = e.Data.GetData(formats[0]) as object;

                // List<DatasetDisplay> listOfDisplayStrings = new List<DatasetDisplay>();
                //  this.ItemsSource = new ListCollectionView(new ObservableCollection<object>());
                ListCollectionView list = this.ItemsSource as ListCollectionView;



                if (sourcedata != null)
                {
                    //Soure and destination are different
                    //if (this != BSkyCanvas.sourceDrag)
                    if (this != BSkyCanvas.sourceDataset)
                    {
                        if (list.IndexOf(sourcedata) < 0)
                        {
                            //  this.ItemsSource = new ListCollectionView(new ObservableCollection<DatasetDisplay>());
                            // ListCollectionView list = this.ItemsSource as ListCollectionView;
                            list.AddNewItem(sourcedata);
                            list.CommitNew();

                            //this.SelectedItem = d;
                            //e.Effects =  DragDropEffects.All;
                            this.ScrollIntoView(sourcedata);//AutoScroll
                        }

                        //Aaron 09/11/2013 Commented 2 lines below
                        //else
                        //   e.Effects =  DragDropEffects.None;
                        //this.UnselectAll();
                        //02/24 Aaron
                        //This is to signify that since the source and destination are different, we have finished the copy.
                        //We will go back to the initiation of the drag and drop to see if the source needs to be removed or kept
                        // in the source listbox. This will be determined by the value of movevariables property
                        e.Effects         = DragDropEffects.Copy;
                        this.SelectedItem = sourcedata;
                        Focus();
                    }

                    //The source and the destination are the same i.e. the target variable
                    else
                    {
                        object destdata = GetDataFromListBox(this, e.GetPosition(this)) as object;
                        if (destdata == sourcedata)
                        {
                            return;
                        }
                        destindex = list.IndexOf(destdata);
                        noofitems = list.Count;
                        object[] newlist = new object[noofitems];
                        sourceindex = list.IndexOf(sourcedata);
                        if (destindex != sourceindex)
                        {
                            //This is the case of move to the end

                            if (destindex == -1)
                            {
                                for (i = 0; i < noofitems; i++)
                                {
                                    if (i == sourceindex)
                                    {
                                        while (i <= (noofitems - 2))
                                        {
                                            newlist[i] = list.GetItemAt(i + 1);
                                            i          = i + 1;
                                        }
                                        newlist[i] = list.GetItemAt(sourceindex);
                                        i          = i + 1;
                                    }

                                    else
                                    {
                                        newlist[i] = list.GetItemAt(i);
                                    }
                                }
                            } //End of move to the end

                            else
                            {
                                if (destindex < sourceindex)
                                {
                                    for (i = 0; i < noofitems; i++)
                                    {
                                        j = i;


                                        if (i == destindex)
                                        {
                                            newlist[i] = list.GetItemAt(sourceindex);
                                            i          = i + 1;


                                            while (j < noofitems)
                                            {
                                                if (j != sourceindex)
                                                {
                                                    newlist[i] = list.GetItemAt(j);
                                                    i          = i + 1;
                                                }
                                                j = j + 1;
                                            }
                                        }

                                        else
                                        {
                                            newlist[i] = list.GetItemAt(i);
                                        }
                                    }
                                } ////End when sourceindex > destindex

                                else if (sourceindex < destindex) //I have tested this
                                {
                                    for (i = 0; i < noofitems; i++)
                                    {
                                        j = i;


                                        if (i == sourceindex)
                                        {
                                            j = j + 1;


                                            while (i < noofitems)
                                            {
                                                if (i == destindex)
                                                {
                                                    newlist[i] = list.GetItemAt(sourceindex);
                                                    i          = i + 1;
                                                }


                                                else
                                                {
                                                    newlist[i] = list.GetItemAt(j);
                                                    j          = j + 1;
                                                    i          = i + 1;
                                                }
                                            }
                                        }


                                        else
                                        {
                                            newlist[i] = list.GetItemAt(i);
                                        }
                                    }

                                    //End of for loop
                                }  //end of destindex > sourceindex

                                //end of else if
                            }

                            //end of else


                            //End of the case move to end
                        }

                        //end of case destindex !=source index
                        if (list.IsAddingNew)
                        {
                            list.CommitNew();
                        }

                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(newlist[i]);
                        }

                        for (i = 0; i < noofitems; i++)
                        {
                            list.AddNewItem(newlist[i]);
                            list.CommitNew();
                            //this.ScrollIntoView(newlist[i]);//AutoScroll
                        }
                        list.Refresh();
                        this.SelectedItem = sourcedata;
                        //02/24 Aaron
                        //This is to signify that since the source and destination is the same, we have performed a move
                        e.Effects = DragDropEffects.Move;
                    }

                    //end of source and destination and the same (target listbox
                }

                //sourcedata |=null
            }

            //formats.length >0
        }
        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);
            }
        }
        //private void ListBox_MouseMove(object sender, MouseButtonEventArgs e)
        //{
        //    if (e.LeftButton == MouseButtonState.Pressed)
        //    {
        //        object data = ((ListBox)(FrameworkElement)sender).SelectedItem;
        //        if (data != null)
        //            DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
        //    }
        //}

        public override void ListBox_Drop(object sender, DragEventArgs e)
        {
            DragDropList             tempDragDropList             = null;
            DragDropListForSummarize tempDragDropListForSummarize = null;
            Boolean autoVarTemp = false;

            if (BSkyCanvas.sourceDrag is DragDropList)
            {
                tempDragDropList = BSkyCanvas.sourceDrag as DragDropList;
                autoVarTemp      = tempDragDropList.AutoVar;
            }
            else if (BSkyCanvas.sourceDrag is DragDropListForSummarize)
            {
                tempDragDropListForSummarize = BSkyCanvas.sourceDrag as DragDropListForSummarize;
                autoVarTemp = tempDragDropListForSummarize.AutoVar;
            }

            string[] formats = e.Data.GetFormats();

            //BSkyCanvas.destDrag = (ListBox)sender;
            //The code below disables drag and drop on the source list, added June 16th
            int destindex, i, j, sourceindex, noofitems;

            System.Windows.Forms.DialogResult diagResult;
            //object[] newlist =null;
            //Aaron Modified 11/04
            //Code below prevents me from doing a move where the source and destination are the source list
            if (AutoVar == false && this == (ListBox)BSkyCanvas.sourceDrag)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            if (formats.Length > 0)
            {
                object             sourcedata = e.Data.GetData(formats[0]) as object;
                ListCollectionView list       = this.ItemsSource as ListCollectionView;

                if (sourcedata != null)
                {
                    //Soure and destination are different. I copy the selected item to the target
                    if ((this != (ListBox)BSkyCanvas.sourceDrag) && (AutoVar == false))
                    {
                        if (list.IndexOf(sourcedata) < 0)
                        {
                            list.AddNewItem(sourcedata);
                            list.CommitNew();

                            //this.SelectedItem = d;
                            //e.Effects =  DragDropEffects.All;
                            this.ScrollIntoView(sourcedata);//AutoScroll
                        }

                        else
                        {
                            e.Effects = DragDropEffects.None;
                        }
                        //this.UnselectAll();
                        //02/24 Aaron
                        //This is to signify that since the source and destination are different, we have finished the copy.
                        //We will go back to the initiation of the drag and drop to see if the source needs to be removed or kept
                        // in the source listbox. This will be determined by the value of movevariables property
                        //e.Effects is set to DragDropEffects.Copy to signify that the selected item has been copies to the destination control
                        e.Effects         = DragDropEffects.Copy;
                        this.SelectedItem = sourcedata;
                        Focus();
                    }

                    //Aaron 09/11/2013
                    //Here I am moving to a target that has 0 or 1 item
                    //If the target has 1 item (it cannot have more than one as I prevent this)
                    //I remove the itemin the target and add it back to the source
                    //ONE OF THE LISTBOXES MUST BE THE SOURCE LISTBOXES
                    else if ((this != (ListBox)BSkyCanvas.sourceDrag) && (AutoVar == true) && (autoVarTemp == false))
                    {
                        ListCollectionView srcList = BSkyCanvas.sourceDrag.ItemsSource as ListCollectionView;
                        noofitems = list.Count;
                        object[] arr = new object[noofitems];

                        //Adding the items in the target to the source before adding new item to the target
                        for (i = 0; i < noofitems; i++)
                        {
                            arr[i] = list.GetItemAt(i);
                            srcList.AddNewItem(arr[i]);
                            srcList.CommitNew();
                        }
                        //Removing all items from the target
                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(arr[i]);
                        }
                        //Adding new item to the target
                        list.AddNewItem(sourcedata);
                        list.CommitNew();
                        // list.Refresh();
                        this.SelectedItem = sourcedata;
                        e.Effects         = DragDropEffects.Copy;
                        Focus();
                    }

                    //Aaron 09/11/2013
                    //If the grouping variable target list box has an item, we want to disallow dragging and dropping from another target to the grouping variable target.
                    //This could crate problems with filter handling
                    //We want to prompt the user to move the variable in teh grouping variable to the source
                    else if ((this != (ListBox)BSkyCanvas.sourceDrag) && (autoVarTemp == true) && (AutoVar == true))
                    {
                        ListCollectionView srcList = BSkyCanvas.sourceDrag.ItemsSource as ListCollectionView;
                        noofitems = list.Count;
                        object[] arr = new object[noofitems];

                        if (noofitems == 1)
                        {
                            diagResult = System.Windows.Forms.MessageBox.Show("Please remove the variable from the grouping variable list before initiating the drag and drop", "Message", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
                            e.Effects  = DragDropEffects.None;
                            BSkyCanvas.sourceDrag.SelectedItem = null;
                            this.Focus();
                            return;
                        }

                        //Adding the items in the target to the source before adding new item to the target
                        for (i = 0; i < noofitems; i++)
                        {
                            arr[i] = list.GetItemAt(i);
                            srcList.AddNewItem(arr[i]);
                            srcList.CommitNew();
                        }
                        //Removing all items from the target
                        for (i = 0; i < noofitems; i++)
                        {
                            list.Remove(arr[i]);
                        }
                        //Adding new item to the target
                        list.AddNewItem(sourcedata);
                        list.CommitNew();
                        // list.Refresh();
                        // this.Focus();
                        this.SelectedItem = sourcedata;
                        e.Effects         = DragDropEffects.Copy;
                        this.Focus();
                    }
                    //The source and the destination are the same i.e. the target variable
                    else
                    {
                        e.Effects = DragDropEffects.None;
                    }
                } //sourcedata |=null
            }
        }