public BSkySortCtrl() { InitializeComponent(); Syntax = "%%VALUE%%"; foreach (object orichild in this.Children) { if (orichild is DragDropListForSummarize) { //vTargetList = child12 as DragDropList; // targetListName = value; //DragList child123; DragDropListForSummarize oriDragDropList = orichild as DragDropListForSummarize; oriDragDropList.ItemsSource = new ListCollectionView(new ObservableCollection <object>()); } } // dragDropList1.summaryCtrl = true; // this.CanExecute = true; //Filter = "String|Numeric|Date|Ordinal|Nominal|Scale"; // TargetAggregate singleItemVar = new TargetAggregate(); // singleItemVar.HorizontalAlignment = HorizontalAlignment.Stretch; // singleItemVar.VerticalAlignment = VerticalAlignment.Stretch; // singleItemVar.AutoVar = true; // singleItemVar.MoveVariables = true; // singleItemVar.renderVars=false; //// singleItemVar.HorizontalAlignment= //// singleItemVar.Width = double.NaN; //// singleItemVar.Height = double.NaN; // oneItemList = singleItemVar; // this.Children.Add(singleItemVar); // // Aaron 09/16/2013 // //A simple way to access the TargetAggregate oject // foreach (object child in this.Children) // { // if (child.GetType().Name == "TargetAggregate") // oneItemList = child as TargetAggregate; // } }
//Added by Aaron 10/02/2015 //The function checkIfAggregateOptionExists checks all the items within the target listbox looking to see if the user //has already selected the aggregate option public bool checkIfAggregateOptionExists(DragDropListForSummarize target, DataSourceVariable sourceitem, string functionName) { string aggregateFunction = ""; int count = 0; int i = 0; DataSourceVariable ds = null; //bool retval = false; aggregateFunction = functionName + "(" + sourceitem.Name + ")"; // target.ite count = target.ItemsCount; foreach (object obj in target.Items) { ds = obj as DataSourceVariable; if (ds.XName == aggregateFunction) { return(true); } //else return false; } return(false); }
//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 } }