/// <summary> /// Removes selected items from collection. /// </summary> private void _RemoveSelectedItems() { // List of selected items. IList selectedItems = _customOrderPropertiesXceedGrid.SelectedItems; // If selected items exist. if (selectedItems != null) { // Remove each selected item from collection of custom order properties. // Note that on deleting item from _customOrderProperties it is also deleted from // _customOrderPropertiesXceedGrid.SelectedItems collection. bool deleteStatus = true; // Iterate while collection is not empty or delete operation is failed. while (selectedItems.Count > 0 && deleteStatus) { IEnumerator enumerator = selectedItems.GetEnumerator(); // Position enumerator to the first item in collection. enumerator.MoveNext(); // Get current item from collection. CustomOrderProperty orderProperty = enumerator.Current as CustomOrderProperty; Debug.Assert(orderProperty != null); // Remove item from collection. deleteStatus = _customOrderProperties.Remove(orderProperty); // Actually each selected item should be deleted successfully. Debug.Assert(deleteStatus); } // while selectedItems = null; } // if }
/// <summary> /// Changes item's name. /// </summary> /// <param name="e">Event arguments.</param> private void _ChangeName(DataGridItemEventArgs e) { // Get custom order property from event's data. CustomOrderProperty orderProperty = e.Item as CustomOrderProperty; Debug.Assert(orderProperty != null); // Check that item's name is null. if (!string.IsNullOrEmpty(orderProperty.Name)) { return; } // Get new item's name. orderProperty.Name = DataObjectNamesConstructor.GetNewNameForCustomOrderProperty(_customOrderProperties, true); // Get current cell. Cell currentCell = _insertionRow.Cells[_customOrderPropertiesXceedGrid.CurrentContext.CurrentColumn]; // Find TextBox inside the cell. TextBox textBox = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell); // Select contents of found text box. if (textBox != null) { textBox.SelectAll(); } }
/// <summary> /// Converts OrderCustomProperty to CustomOrderProperty. /// </summary> /// <param name="orderCustomProperty">OrderCustomProperty object to convert.</param> /// <returns>Converted object.</returns> private CustomOrderProperty _ConvertToCustomOrderProperty(OrderCustomProperty orderCustomProperty) { CustomOrderProperty customOrderPropery = new CustomOrderProperty(); customOrderPropery.Name = orderCustomProperty.Name; customOrderPropery.Type = orderCustomProperty.Type; customOrderPropery.MaxLength = orderCustomProperty.Length; customOrderPropery.Description = orderCustomProperty.Description; customOrderPropery.OrderPairKey = orderCustomProperty.OrderPairKey; return(customOrderPropery); }
/// <summary> /// Stores copy of _customOrderProperties collection: _customOrderPropertiesBackup. /// </summary> private void _BackupCustomOrderPropertiesCollection() { _customOrderPropertiesBackup.Clear(); foreach (CustomOrderProperty item in _customOrderProperties) { // Create a clone of item. CustomOrderProperty itemClone = (CustomOrderProperty)item.Clone(); // Add copy of item into backup collection. _customOrderPropertiesBackup.Add(itemClone); } }
/// <summary> /// Handler for the Xceed.Wpf.DataGrid.DataGridCollectionViewSource.CommittingNewItem event. /// </summary> /// <param name="sender">DataGridCollectionViewSource object.</param> /// <param name="e">Event arguments.</param> private void _DataGridCollectionViewSourceCommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e) { // Get collection of custom order properties bound to the Xceed DataGrid control. ICollection <CustomOrderProperty> source = e.CollectionView.SourceCollection as ICollection <CustomOrderProperty>; // Get custom order property which should be committed to collection. CustomOrderProperty currentProperty = e.Item as CustomOrderProperty; // Add custom order property to collection. source.Add(currentProperty); // Set index of new item in collection. e.Index = source.Count - 1; // Set new count of items in collection. e.NewCount = source.Count; // Set flag indicating that event was handled. e.Handled = true; }
/// <summary> /// Loads custom order properties from collection OrderCustomPropertiesInfo. /// </summary> /// <param name="customPropertiesInfo">OrderCustomPropertiesInfo collection.</param> public void LoadCustomOrderProperties(OrderCustomPropertiesInfo customPropertiesInfo) { Debug.Assert(customPropertiesInfo != null); // Clear collection. _customOrderProperties.Clear(); foreach (OrderCustomProperty orderCustomProperty in customPropertiesInfo) { // Create custom order property using data of item in collection. CustomOrderProperty newOrderProperty = new CustomOrderProperty(orderCustomProperty.Name, orderCustomProperty.Description, orderCustomProperty.Length, orderCustomProperty.OrderPairKey); // Add new custom order property to collection. _customOrderProperties.Add(newOrderProperty); } // Backup collection of custom order properties. _BackupCustomOrderPropertiesCollection(); }