void First() { try { //总页数必须大于1,翻页才有效 if (this.intPageCount > 1) { //清除分配数据 ClearAll(); //当前页为1 intPageNow = 1; //当前页显示 this.txtNow.Text = intPageNow.ToString(); //给分配数据填充 for (int i = (intPageNow - 1) * IntPageSize; i < IntPageSize * intPageNow; i++) { if (i < list.Count) { Collection.AddNewItem(list[i]); } } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "First", ex.ToString()); } finally { } }
public void AddBet(Bet newBet) { if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke(new dAddBet(AddBet), newBet); } else { //if (Bets.CanRemove) while (Bets.Count > UISettings.Settings.LiveBets + 1) { //System.Threading.Thread.Sleep(10); //Bets.Remove(Bets.list); Bets.RemoveAt(Bets.Count - 1); } Bets.AddNewItem(newBet as DiceBet); Bets.CommitNew(); //if (!fitted) { tvBets.BestFitColumns(); fitted = true; } } }
private void AddPerson(object o) { try { ListCollectionView lcv = GetIt <ListCollectionView>(PROP_NAME); if (TryGetViewManager(PROP_NAME, out IManageCViews cViewManager)) { PersonVM newPerson = (PersonVM)cViewManager.GetNewItem(); lcv.AddNewItem(newPerson); lcv.MoveCurrentTo(newPerson); } //if (TryGetViewManager("Business", typeof(PersonDAL), out IManageCViews cViewManager)) //{ // PersonVM newPerson = (PersonVM) cViewManager.GetNewItem(); // lcv.AddNewItem(newPerson); // lcv.MoveCurrentTo(newPerson); //} //else //{ // System.Diagnostics.Debug.WriteLine($"Could not get the view manager -- Fix this message."); //} } catch (Exception ex) { ShowMessage(ex.Message); } }
private void AddBtn_Click(object sender, RoutedEventArgs e) { if (lcv.CanAddNewItem) { foreach (EmployeeInfo info in dataManager.AllEmployeeList) { //离职的不允许添加 if (info.StatusID == 0) { continue; } appLog.Info("Add Employee,ID = " + info.ID); lcv.AddNewItem(new SalaryInfo { Year = (int)(YearComboBox.SelectedItem), Month = (int)(MonthComboBox.SelectedItem), EmployeeID = info.ID, SelectionEmployeeInfoList = dataManager.AllEmployeeList.ToList(), SelectionDepartmentInfoList = dataManager.AllDepartmentList.ToList(), SelectionWorkStatusInfoList = AlgorithmClass.GetWorkStatusList() }); lcv.CommitNew(); } } }
/// <summary> /// Adds the new item to list collection view. /// </summary> /// <param name="theViewToUpdate">The view to update.</param> /// <param name="theNewItem">The new item.</param> public static void AddNewItemToListCollectionView(this ListCollectionView theViewToUpdate, object theNewItem) { theViewToUpdate.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtBeginning; theViewToUpdate.AddNewItem(theNewItem); theViewToUpdate.CommitNew(); theViewToUpdate.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None; }
private void AddCustomers(object obj) { Customers Customers = db.Persons.CreateObject <Customers>(); Customers.FirstName = "New Customer"; db.Persons.AddObject(Customers); _Customerslist.AddNewItem(Customers); _Customerslist.MoveCurrentToLast(); NotifyPropertyChanged("Customer"); }
public void AddItems(IList lst) { ListCollectionView lcw = this.ItemsSource as ListCollectionView; foreach (object obj in lst) { lcw.AddNewItem(obj); } lcw.CommitNew(); }
public bool SaveData() { BillingDataDataContext db = new BillingDataDataContext(); RuntimeData data = null; data = fillData(data); if (data == null) { return(false); } data.SheetNo = sheetNo; data.UserId = SecurityModule.currentUserName; if (!SubClientList.ContainsKey(data.CustCode)) { SubClientList.Add(data.CustCode, new List <string>() { data.SubClient }); } else { if (!SubClientList[data.CustCode].Contains(data.SubClient)) { SubClientList[data.CustCode].Add(data.SubClient); } } if (!ConsignerList.Contains(data.ConsignerName)) { ConsignerList.Add(data.ConsignerName); } if (!ConsigneeList.Contains(data.ConsigneeName)) { ConsigneeList.Add(data.ConsigneeName); } if (dataContext.Where(x => x.ConsignmentNo == data.ConsignmentNo).Count() > 0) { RuntimeData origData = db.RuntimeDatas.SingleOrDefault(x => x.Id == data.Id); dupliData(data, origData); } else { db.RuntimeDatas.InsertOnSubmit(data); dataContext.Add(data); helper.addRecordToCurrentSheet(data); dataListContext.AddNewItem(data); } try { db.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
/// <summary> /// Adds the new items to list collection view. /// </summary> /// <param name="theViewToUpdate">The view to update.</param> /// <param name="theNewList">The new list.</param> public static void AddNewItemsToListCollectionView(this ListCollectionView theViewToUpdate, List <object> theNewList) { theViewToUpdate.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtBeginning; foreach (var item in theNewList) { theViewToUpdate.AddNewItem(item); } theViewToUpdate.CommitNew(); theViewToUpdate.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None; }
void AddCommandExecute(Object parameter) { MainWork mw = parameter as MainWork; ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(mw.lvCredentialInfo.ItemsSource); CredentialInfo newRecord = new CredentialInfo(); lcv.AddNewItem(newRecord); lcv.CommitNew(); SelectedCredential = newRecord; _status = "Add"; Editable = !Editable; mw.lvCredentialInfo.IsEnabled = false; }
public void SupportsExplicitlyImplementedEvents() { var listener = new EventListener(); // ObservableCollection implements ICollectionChanged explicitly var source = new ListCollectionView(new List <int>(new [] { 1, 2, 3 })); WeakEventListener.SubscribeToWeakCollectionChangedEvent(listener, source, listener.OnCollectionChangedEvent); source.AddNewItem(4); Assert.AreEqual(1, listener.CollectionChangedEventCount); }
private void cmd_addItem_Click(object sender, RoutedEventArgs e) { IList <services.DTO_SMS_Template> _temp; List <services.DTO_SMS_Template> _ttt = new List <services.DTO_SMS_Template>(); ListCollectionView _lv = new ListCollectionView(_ttt); _lv.AddNewItem(CGlobalVarible._Template.GetItemAt(dg_customer.SelectedIndex)); _temp = CGlobalVarible._Template.SourceCollection as IList <services.DTO_SMS_Template>; foreach (services.DTO_SMS_Template _t in _temp) { CGlobalVarible.SMS_template = _t.SMS_Template; } sms_message.Text = CGlobalVarible.SMS_template; }
private void AddBtn_Click(object sender, RoutedEventArgs e) { if (lcv.CanAddNewItem) { lcv.AddNewItem(new EmployeeInfo { EmployeeSex = EmployeeSexType.boy, StatusID = 1, DepartmentID = (DepartmentComboBox.SelectedItem as DepartmentInfo).ID, PostID = 1, SelectionPostInfoList = dataManager.AllPostList.ToList(), SelectionDepartmentInfoList = dataManager.AllDepartmentList.ToList(), SelectionWorkStatusInfoList = AlgorithmClass.GetWorkStatusList() }); lcv.CommitNew(); } }
public void AddItem(ErrorSetting error) { var res = lst.AddNewItem(error); //gcErSettings.RefreshData(); }
/// <summary> /// 数据集合视图初始化 /// </summary> /// <param name="datagrid">DataGrid</param> /// <param name="lists">数据</param> /// <param name="pageSize">一页所显示的数据条数</param> public void listInit(DataGrid datagrid, IList lists, int pageSize) { try { this.IntPageSize = pageSize; ListCollectionView coll = new ListCollectionView(lists); this.Collection = coll; if (Collection != null) { #region datapager初始化 //当前页 this.intPageNow = 1; //总页数 this.intPageCount = 0; //数据源 this.list.Clear(); //总页数数量显示 this.txtCount.Text = "1"; //当前页显示 this.txtNow.Text = "1"; #endregion //填充数据源 for (int i = 0; i < Collection.Count; i++) { list.Add(Collection.GetItemAt(i)); } //清除分配数据 ClearAll(); //如果分页的数量比总数量小的话,直接传分页的数量 if (IntPageSize < list.Count) { for (int i = 0; i < IntPageSize; i++) { Collection.AddNewItem(list[i]); } } //如果分页的数量比总页大的话,直接传总页的数量 else { for (int i = 0; i < list.Count; i++) { Collection.AddNewItem(list[i]); } } #region 设置信息显示(总页数,当前页位置) //获取总页数 intPageCount = (int)Math.Ceiling((double)list.Count / IntPageSize); this.txtCount.Text = intPageCount.ToString(); //当前页 this.txtNow.Text = intPageNow.ToString(); #endregion Collection.AddNewItem(null); Collection.CancelNew(); } datagrid.ItemsSource = coll; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "listInit", ex.ToString()); } finally { } }
//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 } }
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 }
/// <summary> /// 数据集合视图初始化 /// </summary> /// <param name="datagrid">DataGrid</param> /// <param name="lists">数据</param> /// <param name="pageSize">一页所显示的数据</param> public void listInit(DataGrid datagrid, IList lists, int pageSize) { try { #region 添加加载页功能 datagrid.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(datagrid_ScrollChanged)); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += new EventHandler(timer_Tick); #endregion this.IntPageSize = pageSize; ListCollectionView coll = new ListCollectionView(lists); this.Collection = coll; if (Collection != null) { #region datapager初始化 //当前页 this.intPageNow = 1; //总页数 this.intPageCount = 0; //数据源 this.list.Clear(); //总页数数量显示 //this.txtCount.Text = "1"; //当前页显示 //this.txtNow.Text = "1"; #endregion //填充数据源 for (int i = 0; i < collection.Count; i++) { list.Add(collection.GetItemAt(i)); } //清除分配数据 ClearAll(); //如果分页的数量比总数量小的话,直接传分页的数量 if (IntPageSize < list.Count) { for (int i = 0; i < IntPageSize; i++) { Collection.AddNewItem(list[i]); } } //如果分页的数量比总页大的话,直接传总页的数量 else { for (int i = 0; i < list.Count; i++) { Collection.AddNewItem(list[i]); } } #region 设置信息显示(总页数,当前页位置) //获取总页数 intPageCount = (int)Math.Ceiling((double)list.Count / IntPageSize); //this.txtCount.Text = intPageCount.ToString(); //当前页 //this.txtNow.Text = intPageNow.ToString(); txtAllcount.Text = list.Count.ToString(); #endregion Collection.AddNewItem(null); Collection.CancelNew(); } datagrid.ItemsSource = coll; } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "listInit", ex.ToString()); } finally { } }
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 }