Exemplo n.º 1
0
 public static Item InventoryRow(this System.Windows.Controls.DataGridCellInfo cell)
 {
     if (cell.Item == CollectionView.NewItemPlaceholder)
     {
         return(null);
     }
     return(cell.Item as Item);
 }
        static public int GetRowIndex(DataGrid dataGrid, DataGridCellInfo dataGridCellInfo)
        {
            DataGridRow dgrow = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGridCellInfo.Item);
            if (dgrow != null)
                return dgrow.GetIndex();

            return -1;
        }
Exemplo n.º 3
0
        private void BtnSet_Click(object sender, RoutedEventArgs e)
        {
            //DataGridCell cell = new DataGridCell();
            //cell.Column = dgTest.Columns[3];

            DataGridCellInfo cInfo = new DataGridCellInfo(dgTest, dgTest.Columns[3]);
            dgTest.CurrentCell = cInfo;
        }
Exemplo n.º 4
0
        private void BtnGet_Click(object sender, RoutedEventArgs e)
        {
            dgTest.SelectedCells.Clear();
            DataGridCellInfo cInfo = new DataGridCellInfo();

            for (int j = 0; j < 25; j++)
            {
                for (int i = 0; i < dgTest.Columns.Count; i++)
                {
                    cInfo = new DataGridCellInfo(dgTest.Items[j], dgTest.Columns[i]);
                    dgTest.SelectedCells.Add(cInfo);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据目标单元格的值, 填充到选中的单元格
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datagrid"></param>
        public static void CopyValueFromSourceCell(this System.Windows.Controls.DataGrid datagrid)
        {
            if (datagrid == null)
            {
                throw new Exception("DataGrid为空");
            }

            if (datagrid.SelectedCells == null || datagrid.SelectedCells.Count <= 0)
            {
                throw new Exception("未选中任何单元格。");
            }

            if (datagrid.CurrentCell == null)
            {
                throw new Exception("未选中任何单元格。");
            }

            object valueToFillAll = null;

            if (datagrid.Tag == null)
            {
                throw new Exception("请先设置复制目标单元格。");
            }

            var matchTag = datagrid.Tag as DataGridTag;

            if (matchTag.SourceCell == null)
            {
                throw new Exception("请先设置目标单元格。");
            }
            else
            {
                string matchField = GetBindingPath(matchTag.SourceCell.Column);
                var    model      = matchTag.SourceCell.Item;
                valueToFillAll = GetValue_DiGui(model, matchField);
            }

            if (valueToFillAll == null)
            {
                throw new Exception("请先设置目标单元格。");
            }

            for (int index = 0; index < datagrid.SelectedCells.Count; index++)
            {
                DataGridCellInfo cellInfo   = datagrid.SelectedCells[index];
                string           matchField = GetBindingPath(cellInfo.Column);
                object           model      = cellInfo.Item;
                SetValue_DiGui(model, matchField, valueToFillAll, index);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Función pública estática, que nos devuelve una celda 
 /// seleccionada en el control DataGrid.
 /// </summary>
 /// <remarks>
 /// Sin comentarios adicionales.
 /// </remarks>
 /// <param name="dataGridCellInfo">
 /// Información de la celda del control DataGrid.
 /// </param>
 /// <returns>
 /// Celda seleccionada.
 /// </returns>
 public static DataGridCell GetCell(DataGridCellInfo dataGridCellInfo)
 {
     if (!dataGridCellInfo.IsValid)
     {
         return null;
     }
     var cellContent = dataGridCellInfo.Column.GetCellContent(dataGridCellInfo.Item);
     if (cellContent != null)
     {
         return (DataGridCell)cellContent.Parent;
     }
     else
     {
         return null;
     }
 } // GetCell
        void ISelectionItemProvider.AddToSelection() 
        { 
            if (!IsCellSelectionUnit)
            { 
                throw new InvalidOperationException(SR.Get(SRID.DataGrid_CannotSelectCell));
            }

            // If item is already selected - do nothing 
            DataGridCellInfo currentCellInfo = new DataGridCellInfo(_item, _column);
            if (this.OwningDataGrid.SelectedCellsInternal.Contains(currentCellInfo)) 
            { 
                return;
            } 

            EnsureEnabled();

            if (this.OwningDataGrid.SelectionMode == DataGridSelectionMode.Single && 
                this.OwningDataGrid.SelectedCells.Count > 0)
            { 
                throw new InvalidOperationException(); 
            }
 
            this.OwningDataGrid.SelectedCellsInternal.Add(currentCellInfo);
        }
Exemplo n.º 8
0
 /// <summary>
 ///     Notification that a particular cell's IsSelected property changed.
 /// </summary>
 internal void CellIsSelectedChanged(DataGridCell cell, bool isSelected)
 {
     if (!IsUpdatingSelectedCells)
     {
         DataGridCellInfo cellInfo = new DataGridCellInfo(cell);
         if (isSelected)
         {
             _selectedCells.AddValidatedCell(cellInfo);
         }
         else if (_selectedCells.Contains(cellInfo))
         {
             _selectedCells.Remove(cellInfo);
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        ///     Process selection on a cell.
        ///     Depending on the current keyboard state, this may mean
        ///     - Selecting the cell
        ///     - Deselecting the cell
        ///     - Deselecting other cells
        ///     - Extending selection to the cell
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem
        ///     is to try to use the previously computed row index if the operations
        ///     are in the same row scope.
        /// </remarks>
        private void MakeCellSelection(DataGridCellInfo cellInfo, bool allowsExtendSelect, bool allowsMinimalSelect)
        {
            bool extendSelection = allowsExtendSelect && ShouldExtendSelection;

            // minimalModify means that previous selections should not be cleared
            // or that the particular item should be toggled.
            bool minimalModify = allowsMinimalSelect && ShouldMinimallyModifySelection;

            using (UpdateSelectedCells())
            {
                int cellInfoColumnIndex = cellInfo.Column.DisplayIndex;
                if (extendSelection)
                {
                    // Extend selection from the anchor to the cell
                    ItemCollection items = Items;

                    int startIndex = _selectionAnchor.Value.ItemInfo.Index;
                    int endIndex = cellInfo.ItemInfo.Index;

                    DataGridColumn anchorColumn = _selectionAnchor.Value.Column;
                    int startColumnIndex = anchorColumn.DisplayIndex;
                    int endColumnIndex = cellInfoColumnIndex;

                    if ((startIndex >= 0) && (endIndex >= 0) &&
                        (startColumnIndex >= 0) && (endColumnIndex >= 0))
                    {
                        int newRowCount = Math.Abs(endIndex - startIndex) + 1;
                        int newColumnCount = Math.Abs(endColumnIndex - startColumnIndex) + 1;

                        if (!minimalModify)
                        {
                            // When extending cell selection, clear out any selected items
                            if (SelectedItems.Count > 0)
                            {
                                UnselectAll();
                            }

                            _selectedCells.Clear();
                        }
                        else
                        {
                            // Remove the previously selected region
                            int currentCellIndex = CurrentCell.ItemInfo.Index;
                            int currentCellColumnIndex = CurrentCell.Column.DisplayIndex;

                            int previousStartIndex = Math.Min(startIndex, currentCellIndex);
                            int previousRowCount = Math.Abs(currentCellIndex - startIndex) + 1;
                            int previousStartColumnIndex = Math.Min(startColumnIndex, currentCellColumnIndex);
                            int previousColumnCount = Math.Abs(currentCellColumnIndex - startColumnIndex) + 1;

                            _selectedCells.RemoveRegion(previousStartIndex, previousStartColumnIndex, previousRowCount, previousColumnCount);

                            if (SelectionUnit == DataGridSelectionUnit.CellOrRowHeader)
                            {
                                int removeRowStartIndex = previousStartIndex;
                                int removeRowEndIndex = previousStartIndex + previousRowCount - 1;

                                if (previousColumnCount <= newColumnCount)
                                {
                                    // When no columns were removed, we can check fewer rows
                                    if (previousRowCount > newRowCount)
                                    {
                                        // One or more rows were removed, so only check those rows
                                        int removeCount = previousRowCount - newRowCount;
                                        removeRowStartIndex = (previousStartIndex == currentCellIndex) ? currentCellIndex : currentCellIndex - removeCount + 1;
                                        removeRowEndIndex = removeRowStartIndex + removeCount - 1;
                                    }
                                    else
                                    {
                                        // No rows were removed, so don't check anything
                                        removeRowEndIndex = removeRowStartIndex - 1;
                                    }
                                }

                                // For cells that were removed, check if their row is selected
                                for (int i = removeRowStartIndex; i <= removeRowEndIndex; i++)
                                {
                                    object item = Items[i];
                                    if (SelectedItems.Contains(item))
                                    {
                                        // When a cell in a row is unselected, unselect the row too
                                        SelectedItems.Remove(item);
                                    }
                                }
                            }
                        }

                        // Select the cells in rows within the selection range
                        _selectedCells.AddRegion(Math.Min(startIndex, endIndex), Math.Min(startColumnIndex, endColumnIndex), newRowCount, newColumnCount);
                    }
                }
                else
                {
                    bool selectedCellsContainsCellInfo = _selectedCells.Contains(cellInfo);
                    bool singleRowOperation = (_editingRowInfo != null && _editingRowInfo.Index == cellInfo.ItemInfo.Index);
                    if (!selectedCellsContainsCellInfo &&
                        singleRowOperation)
                    {
                        // ADO.Net bug workaround, see remarks.
                        selectedCellsContainsCellInfo = _selectedCells.Contains(_editingRowInfo.Index, cellInfoColumnIndex);
                    }

                    if (minimalModify && selectedCellsContainsCellInfo)
                    {
                        // Unselect the one cell
                        if (singleRowOperation)
                        {
                            // ADO.Net bug workaround, see remarks.
                            _selectedCells.RemoveRegion(_editingRowInfo.Index, cellInfoColumnIndex, 1, 1);
                        }
                        else
                        {
                            _selectedCells.Remove(cellInfo);
                        }

                        if ((SelectionUnit == DataGridSelectionUnit.CellOrRowHeader) &&
                            SelectedItems.Contains(cellInfo.Item))
                        {
                            // When a cell in a row is unselected, unselect the row too
                            SelectedItems.Remove(cellInfo.Item);
                        }
                    }
                    else
                    {
                        if (!minimalModify || !CanSelectMultipleItems)
                        {
                            // Unselect any items
                            if (SelectedItems.Count > 0)
                            {
                                UnselectAll();
                            }

                            // Unselect all the other cells
                            _selectedCells.Clear();
                        }

                        if (singleRowOperation)
                        {
                            // ADO.Net bug workaround, see remarks.
                            _selectedCells.AddRegion(_editingRowInfo.Index, cellInfoColumnIndex, 1, 1);
                        }
                        else
                        {
                            // Select the cell
                            _selectedCells.AddValidatedCell(cellInfo);
                        }
                    }

                    _selectionAnchor = new DataGridCellInfo(cellInfo);
                }
            }
        }
Exemplo n.º 10
0
		/// <summary>
		///     Begins editing a string entry.
		/// </summary>
		/// <param name="entry">The entry to begin editing.</param>
		private void StartEditing(StringEntry entry)
		{
			var cell = new DataGridCellInfo(entry, stringIdColumn);
			lvLocales.ScrollIntoView(entry);
			lvLocales.Focus();
			lvLocales.CurrentCell = cell;
			lvLocales.BeginEdit();
		}
Exemplo n.º 11
0
 internal void SelectOnlyThisCell(DataGridCellInfo currentCellInfo)
 {
     using (UpdateSelectedCells())
     {
         _selectedCells.Clear();
         _selectedCells.Add(currentCellInfo);
     }
 }
Exemplo n.º 12
0
 private DataGridCell TryFindCell(DataGridCellInfo info) 
 {
     // Does not de-virtualize cells 
     return TryFindCell(info.Item, info.Column); 
 }
Exemplo n.º 13
0
        public DataGridCell GetDataGridCell (DataGridCellInfo cellInfo) {
            var cellContent = cellInfo.Column.GetCellContent(cellInfo.Item);
            if (cellContent != null)
                return (DataGridCell)cellContent.Parent;

            return null;
        }
Exemplo n.º 14
0
        private void dgvAuxTools_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                int columnDisplayIndex = dgvAuxTools.CurrentCell.Column.DisplayIndex;

                //if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift))  //original
                if ((e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) || e.Key == Key.Left)
                {
                    //new
                    if (e.Key == Key.Left)
                    {
                        try
                        {
                            System.Windows.Controls.DataGridCellInfo dgt = dgvToolSchedule.CurrentCell;
                            var cellContent = (TextBox)dgt.Column.GetCellContent(dgt.Item);
                            //cellContent.SelectionLength
                            if (cellContent != null)
                            {
                                if (cellContent.SelectionLength != cellContent.Text.Length)
                                {
                                    return;
                                }
                                //new by me

                                //    TextBox
                                //end new by me
                            }
                        }
                        catch (Exception ex)
                        {
                            return;
                        }
                    }
                    //end new
                    e.Handled          = true;
                    columnDisplayIndex = dgvAuxTools.CurrentCell.Column.DisplayIndex;
                    if (columnDisplayIndex == 0)
                    {
                        dgvAuxTools.SelectedIndex = dgvAuxTools.SelectedIndex - 1;
                        columnDisplayIndex        = dgvAuxTools.Columns.Count - 1;
                    }
                    else
                    {
                        if (columnDisplayIndex == 1)
                        {
                            columnDisplayIndex = 0;
                        }
                        else
                        {
                            columnDisplayIndex = columnDisplayIndex - 1;
                        }
                    }
                    System.Windows.Controls.DataGridColumn nextColumn = dgvAuxTools.ColumnFromDisplayIndex(columnDisplayIndex);

                    // now telling the grid, that we handled the key down event
                    //e.Handled = true;

                    // setting the current cell (selected, focused)
                    dgvAuxTools.CurrentCell = new System.Windows.Controls.DataGridCellInfo(dgvAuxTools.SelectedItem, nextColumn);

                    // tell the grid to initialize edit mode for the current cell
                    dgvAuxTools.BeginEdit();
                }

                //else if (e.Key == Key.Enter || e.Key == Key.Tab) //original
                else if (e.Key == Key.Enter || e.Key == Key.Tab || e.Key == Key.Right)
                {
                    if (e.Key == Key.Right)
                    {
                        try
                        {
                            System.Windows.Controls.DataGridCellInfo dgt = dgvToolSchedule.CurrentCell;
                            var cellContent = (TextBox)dgt.Column.GetCellContent(dgt.Item);
                            //cellContent.SelectionLength
                            if (cellContent != null)
                            {
                                if (cellContent.SelectionLength != cellContent.Text.Length)
                                {
                                    return;
                                }

                                //    TextBox
                            }
                        }
                        catch (Exception ex)
                        {
                            return;
                        }
                    }
                    //end add by nandakumar
                    //System.Windows.Controls.DataGridColumn nextColumn = dgvAuxTools.ColumnFromDisplayIndex(columnDisplayIndex);

                    //// now telling the grid, that we handled the key down event
                    ////e.Handled = true;

                    //// setting the current cell (selected, focused)
                    //dgvAuxTools.CurrentCell = new System.Windows.Controls.DataGridCellInfo(dgvAuxTools.SelectedItem, nextColumn);

                    //// tell the grid to initialize edit mode for the current cell
                    //dgvAuxTools.BeginEdit();

                    if (columnDisplayIndex == 6)
                    {
                        columnDisplayIndex        = 0;
                        dgvAuxTools.SelectedIndex = dgvAuxTools.SelectedIndex + 1;
                    }
                    else
                    {
                        columnDisplayIndex = columnDisplayIndex + 1;
                    }
                    int selectedIndex = 0;
                    selectedIndex = dgvAuxTools.SelectedIndex;

                    System.Windows.Controls.DataGridColumn nextColumn = dgvAuxTools.ColumnFromDisplayIndex(columnDisplayIndex);
                    // now telling the grid, that we handled the key down event
                    e.Handled = true;
                    // setting the current cell (selected, focused)
                    dgvAuxTools.CurrentCell = new System.Windows.Controls.DataGridCellInfo(dgvAuxTools.SelectedItem, nextColumn);
                    dgvAuxTools.ScrollIntoView(dgvAuxTools.CurrentCell);
                    // tell the grid to initialize edit mode for the current cell
                    dgvAuxTools.BeginEdit();
                }
            }
            catch (Exception ex)
            {
                ex.LogException();
            }
        }
 // Preemptively updates the corresponding item's property when a data grid check box is checked or unchecked.
 private void DataGridCheckBoxCheckedChanged(DataGridCell cell, bool isChecked)
 {
     DataGridCellInfo cellInfo = new DataGridCellInfo(cell);
     string currentColumnHeader = cellInfo.Column.Header.ToString();
     PropertyInfo property = cellInfo.Item.GetType().GetProperties().Single(propertyInfo => propertyInfo.Name == currentColumnHeader);
     property.SetValue(cellInfo.Item, isChecked, null);
 }
        private void DataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            // Nothing selected?
            if (e.AddedCells.Count == 0) { return; }

            // Prevent user from selecting the first "subtype" column
            SubtypeDataGridColumn colum = e.AddedCells[0].Column as SubtypeDataGridColumn;
            if (colum != null) {
                if (e.RemovedCells.Count != 0) {
                    DataGrid dg = sender as DataGrid;
                    DataGridCellInfo ci = e.RemovedCells[0];
                    DataGridCellInfo cell = new DataGridCellInfo(ci.Item, ci.Column);
                    dg.CurrentCell = cell;
                    dg.SelectedCells.Clear();
                    dg.SelectedCells.Add(cell);
                    return;
                }
            }

            // Update the selected junction/edge dependancy property
            if (sender == this.DataGridJunctionRules) {
                GeometricNetworkViewModel.Default.SelectedJunctionRule = this.GetSelectedRule(this.DataGridJunctionRules) as ZJunctionConnectivityRule;
            }
            else if (sender == this.DataGridEdgeRules) {
                GeometricNetworkViewModel.Default.SelectedEdgeRule = this.GetSelectedRule(this.DataGridEdgeRules) as ZEdgeConnectivityRule;
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender == this.MenuItemExit) {
                if (GeometricNetworkViewModel.Default.IsDirty) {
                    MessageBoxResult r = MessageBox.Show(
                        "Do you want to save before closing?",
                        GeometricNetworkViewModel.Default.WindowTitle,
                        MessageBoxButton.YesNoCancel,
                        MessageBoxImage.Exclamation,
                        MessageBoxResult.Yes
                    );
                    switch (r) {
                        case MessageBoxResult.Yes:
                            // Save document
                            GeometricNetworkViewModel.Default.Save();

                            // If user canceled save dialog then exit
                            if (GeometricNetworkViewModel.Default.IsDirty) { return; }

                            break;
                        case MessageBoxResult.No:
                            break;
                        case MessageBoxResult.Cancel:
                        default:
                            return;
                    }
                }

                // Exit application
                Application.Current.Shutdown(0);
            }
            else if (sender == this.ButtonOpen) {
                // Exit if dataset already open
                if (GeometricNetworkViewModel.Default.Dataset != null) {
                    MessageBox.Show(
                        "Please close the document first",
                        GeometricNetworkViewModel.Default.WindowTitle,
                        MessageBoxButton.OK,
                        MessageBoxImage.Information,
                        MessageBoxResult.OK
                    );
                    return;
                }

                OpenFileDialog openFileDialog = new OpenFileDialog() {
                    CheckFileExists = true,
                    Filter = "GN definition document" + " (*.esriGeoNet)|*.esriGeoNet",
                    FilterIndex = 1,
                    Multiselect = false,
                    Title = GeometricNetworkViewModel.Default.WindowTitle
                };

                // Check if user pressed "Save" and File is OK.
                bool? ok = openFileDialog.ShowDialog(this);
                if (!ok.HasValue || !ok.Value) { return; }
                if (string.IsNullOrWhiteSpace(openFileDialog.FileName)) { return; }

                //
                GeometricNetworkViewModel.Default.Load(openFileDialog.FileName);
            }
            else if (sender == this.ButtonSave) {
                // Handle event to prevent bubbling event to ButtonSave
                if (e != null) {
                    e.Handled = true;
                }

                // Exit if no dataset
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }

                // If no document, show "save as" dialog
                if (GeometricNetworkViewModel.Default.Document == null) {
                    this.Button_Click(this.ButtonSaveAs, null);
                    return;
                }

                // Save document
                GeometricNetworkViewModel.Default.Save();
            }
            else if (sender == this.ButtonSaveAs) {
                // Handle event to prevent bubbling event to ButtonSave
                if (e != null) {
                    e.Handled = true;
                }

                // Show save dialog
                SaveFileDialog saveFileDialog = new SaveFileDialog() {
                    DefaultExt = "esriGeoNet",
                    FileName = "Document1",
                    Filter = "GN definition document" + " (*.esriGeoNet)|*.esriGeoNet",
                    FilterIndex = 1,
                    OverwritePrompt = true,
                    RestoreDirectory = false,
                    Title = GeometricNetworkViewModel.Default.WindowTitle
                };

                // Check if user pressed "Save" and File is OK.
                bool? ok = saveFileDialog.ShowDialog(this);
                if (!ok.HasValue || !ok.Value) { return; }
                if (string.IsNullOrWhiteSpace(saveFileDialog.FileName)) { return; }

                //
                GeometricNetworkViewModel.Default.Save(saveFileDialog.FileName);
            }
            else if (sender == this.ButtonClose) {
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }
                if (GeometricNetworkViewModel.Default.IsDirty) {
                    MessageBoxResult r = MessageBox.Show(
                        "Do you want to save before closing?",
                        GeometricNetworkViewModel.Default.WindowTitle,
                        MessageBoxButton.YesNoCancel,
                        MessageBoxImage.Exclamation,
                        MessageBoxResult.Yes
                    );
                    switch (r) {
                        case MessageBoxResult.Yes:
                            GeometricNetworkViewModel.Default.Save();
                            break;
                        case MessageBoxResult.No:
                            break;
                        case MessageBoxResult.Cancel:
                        default:
                            return;
                    }
                }

                // Clear current dataset
                GeometricNetworkViewModel.Default.Clear();
            }
            else if (sender == this.ButtonImport) {
                // Create GxObjectFilter for GxDialog
                IGxObjectFilter gxObjectFilter = new GxFilterGeometricNetworksClass();

                // Create GxDialog
                IGxDialog gxDialog = new GxDialogClass() {
                    AllowMultiSelect = false,
                    ButtonCaption = "Import",
                    ObjectFilter = gxObjectFilter,
                    RememberLocation = true,
                    Title = "Please select a geometric network"
                };

                // Declare Enumerator to hold selected objects
                IEnumGxObject enumGxObject = null;

                // Open Dialog
                if (!gxDialog.DoModalOpen(0, out enumGxObject)) { return; }
                if (enumGxObject == null) { return; }

                // Get Selected Object (if any)
                IGxObject gxObject = enumGxObject.Next();
                if (gxObject == null) { return; }
                if (!gxObject.IsValid) { return; }

                // Get GxDataset
                if (!(gxObject is IGxDataset)) { return; }
                IGxDataset gxDataset = (IGxDataset)gxObject;

                // Load geometric network from named object
                IName name = (IName)gxDataset.DatasetName;
                GeometricNetworkLoader loader = new GeometricNetworkLoader(name);
                loader.Load();
            }
            else if (sender == this.ButtonExport) {
                ResultType ok = this.ExportGeometricNetwork();
                switch (ok) {
                    case ResultType.Cancelled:
                        break;
                    case ResultType.Error:
                        MessageBox.Show(
                            "Geometric network creation failed",
                            GeometricNetworkViewModel.Default.WindowTitle,
                            MessageBoxButton.OK,
                            MessageBoxImage.Information,
                            MessageBoxResult.OK
                        );
                        break;
                    case ResultType.Successful:
                        MessageBox.Show(
                           "Geometric network creation successful",
                           GeometricNetworkViewModel.Default.WindowTitle,
                           MessageBoxButton.OK,
                           MessageBoxImage.Information,
                           MessageBoxResult.OK
                       );
                        break;
                }
            }
            else if (sender == this.ButtonOutput) {
                if (this.DockableContentOutput.IsHidden) {
                    this.DockableContentOutput.Show();
                }
                else if (this.DockableContentOutput.IsAutoHidden) {
                    this.DockableContentOutput.ToggleAutoHide();
                }
            }
            else if (sender == this.ButtonJunctionAdd) {
                // Exit if invalid
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }
                if (GeometricNetworkViewModel.Default.SelectedJunctionRule != null) { return; }

                // Add junction rule
                if (this.DataGridJunctionRules.SelectedCells == null) { return; }
                if (this.DataGridJunctionRules.SelectedCells.Count == 0) { return; }
                DataGridCellInfo ci = this.DataGridJunctionRules.SelectedCells[0];
                object o = ci.Item;
                if (o == null) { return; }

                RuleDataGridColumn rdgc = ci.Column as RuleDataGridColumn;
                if (rdgc == null) { return; }

                ZGeometricNetwork zgn = GeometricNetworkViewModel.Default.Dataset as ZGeometricNetwork;
                if (zgn == null) { return; }

                // Create new rule
                ZSubtype e1 = o.GetType().GetProperty(RuleMatrix.EDGE_SUBTYPE).GetValue(o, null) as ZSubtype;
                ZSubtype j1 = zgn.FindSubtype(rdgc.ColumnName);
                ZJunctionConnectivityRule rule = new ZJunctionConnectivityRule(e1, j1);

                // Add rule to network
                zgn.JunctionRules.Add(rule);

                // Update data source
                o.GetType().GetProperty(rdgc.ColumnName).SetValue(o, rule, null);

                // Refresh display
                GeometricNetworkViewModel.Default.SelectedJunctionRule = (ZJunctionConnectivityRule)rule;
                GeometricNetworkViewModel.Default.JunctionRuleDataSource.Refresh();

                // Focus cell
                DataGridCellInfo cell = new DataGridCellInfo(o, rdgc);
                this.DataGridJunctionRules.CurrentCell = cell;
                this.DataGridJunctionRules.SelectedCells.Clear();
                this.DataGridJunctionRules.SelectedCells.Add(cell);

                // Make document dirty
                GeometricNetworkViewModel.Default.MakeDirty();
            }
            else if (sender == this.ButtonJunctionRemove) {
                // Exit if invalid
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }
                if (GeometricNetworkViewModel.Default.SelectedJunctionRule == null) { return; }

                // Get selected cell
                if (this.DataGridJunctionRules.SelectedCells == null) { return; }
                if (this.DataGridJunctionRules.SelectedCells.Count == 0) { return; }
                DataGridCellInfo ci = this.DataGridJunctionRules.SelectedCells[0];
                object o = ci.Item;
                if (o == null) { return; }

                // Get selected rule
                RuleDataGridColumn rdgc = ci.Column as RuleDataGridColumn;
                if (rdgc == null) { return; }
                ZRule rule = o.GetType().GetProperty(rdgc.ColumnName).GetValue(o, null) as ZRule;
                if (rule == null) { return; }

                // Update data source
                o.GetType().GetProperty(rdgc.ColumnName).SetValue(o, null, null);

                // Remove from dataset
                ZGeometricNetwork zgn = GeometricNetworkViewModel.Default.Dataset as ZGeometricNetwork;
                if (zgn == null) { return; }
                zgn.JunctionRules.Remove(rule);

                // Refresh display
                GeometricNetworkViewModel.Default.SelectedJunctionRule = (ZJunctionConnectivityRule)rule;
                GeometricNetworkViewModel.Default.JunctionRuleDataSource.Refresh();

                // Focus cell
                DataGridCellInfo cell = new DataGridCellInfo(o, rdgc);
                this.DataGridJunctionRules.CurrentCell = cell;
                this.DataGridJunctionRules.SelectedCells.Clear();
                this.DataGridJunctionRules.SelectedCells.Add(cell);

                // Make document dirty
                GeometricNetworkViewModel.Default.MakeDirty();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 区域粘贴
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datagrid"></param>
        public static void AreaPaste(this System.Windows.Controls.DataGrid datagrid)
        {
            if (datagrid == null)
            {
                throw new Exception("DataGrid为空");
            }

            if (datagrid.SelectedCells == null || datagrid.SelectedCells.Count <= 0)
            {
                throw new Exception("未选中任何单元格。");
            }

            if (datagrid.CurrentCell == null)
            {
                throw new Exception("未选中任何单元格。");
            }

            int datagridSelectedCellsCount = datagrid.SelectedCells.Count;

            List <string> clipBoardContentList = new List <string>();

            #region 粘贴区域

            string pasteText = System.Windows.Clipboard.GetText();

            if (string.IsNullOrEmpty(pasteText) == true)
            {
                throw new Exception("剪贴板无信息。");
            }

            if (pasteText.Contains('\r') == true || pasteText.Contains('\n') == true)
            {
                List <string> splited = pasteText.Split('\r', '\n')
                                        .Select(i => i.Trim())
                                        .Where(i => string.IsNullOrEmpty(i) == false)
                                        .ToList();
                ;

                clipBoardContentList.Clear();
                clipBoardContentList.AddRange(splited);
            }
            else
            {
                clipBoardContentList.Add(pasteText);
            }

            #endregion 粘贴区域

            if (datagridSelectedCellsCount != clipBoardContentList.Count)
            {
                var errorMsg = string.Format("无法粘贴。选中{0}格, 粘贴{1}格。", datagridSelectedCellsCount, clipBoardContentList.Count);
                throw new Exception(errorMsg);
            }

            // Cell ==> Prop
            for (int index = 0; index < clipBoardContentList.Count; index++)
            {
                DataGridCellInfo cellInfo   = datagrid.SelectedCells[index];
                string           matchField = GetBindingPath(cellInfo.Column);
                string           value      = clipBoardContentList[index];
                object           model      = cellInfo.Item;
                SetValue_DiGui(model, matchField, value, index);
            }
        }
        void ISelectionItemProvider.RemoveFromSelection() 
        {
            if (!IsCellSelectionUnit) 
            { 
                throw new InvalidOperationException(SR.Get(SRID.DataGrid_CannotSelectCell));
            } 

            EnsureEnabled();

            DataGridCellInfo currentCellInfo = new DataGridCellInfo(_item, _column); 
            if (this.OwningDataGrid.SelectedCellsInternal.Contains(currentCellInfo))
            { 
                this.OwningDataGrid.SelectedCellsInternal.Remove(currentCellInfo); 
            }
        } 
 /// <summary>
 ///     Used to create a copy of an existing DataGridCellInfo, with its own
 ///     ItemInfo (to avoid aliasing).
 /// </summary>
 internal DataGridCellInfo(DataGridCellInfo info)
 {
     _info   = info._info.Clone();
     _column = info._column;
     _owner  = info._owner;
 }
        void ISelectionItemProvider.Select()
        {
            if (!IsCellSelectionUnit) 
            {
                throw new InvalidOperationException(SR.Get(SRID.DataGrid_CannotSelectCell)); 
            } 

            EnsureEnabled(); 

            DataGridCellInfo currentCellInfo = new DataGridCellInfo(_item, _column);
            this.OwningDataGrid.SelectOnlyThisCell(currentCellInfo);
        } 
 internal bool EqualsImpl(DataGridCellInfo cell)
 {
     return((cell._column == _column) && (cell.Owner == Owner) && (cell._info == _info));
 }
Exemplo n.º 23
0
 public void gotFocus(object sender, EventArgs args)
 {
     this.ParentForm.LastFocusedElement = this;
     this._lastFocused = _dgrid.CurrentCell;
 }
Exemplo n.º 24
0
 private static bool CellInfoNeedsAdjusting(DataGridCellInfo cellInfo)
 {
     ItemsControl.ItemInfo info = cellInfo.ItemInfo;
     return (info != null) && (info.Index != -1);
 }
Exemplo n.º 25
0
        /// <summary>
        ///     Updates the IsSelected property on cells due to a change in SelectedCells.
        /// </summary>
        private void UpdateIsSelected(VirtualizedCellInfoCollection cells, bool isSelected)
        {
            if (cells != null)
            {
                int numCells = cells.Count;
                if (numCells > 0)
                {
                    // Determine if it would be better to iterate through all the visible cells
                    // instead of through the update list.
                    bool useTracker = false;

                    // For "small" updates it's simpler to just go through the cells, get the container,
                    // and update IsSelected. For "large" updates, it's faster to go through the visible
                    // cells, see if they're in the collection, and then update IsSelected.
                    // Determining small vs. large is going to be done using a magic number.
                    // 750 is close to the number of visible cells Excel shows by default on a 1280x1024 monitor.
                    if (numCells > 750)
                    {
                        int numTracker = 0;
                        int numColumns = _columns.Count;

                        ContainerTracking<DataGridRow> rowTracker = _rowTrackingRoot;
                        while (rowTracker != null)
                        {
                            numTracker += numColumns;
                            if (numTracker >= numCells)
                            {
                                // There are more cells visible than being updated
                                break;
                            }

                            rowTracker = rowTracker.Next;
                        }

                        useTracker = (numCells > numTracker);
                    }

                    if (useTracker)
                    {
                        ContainerTracking<DataGridRow> rowTracker = _rowTrackingRoot;
                        while (rowTracker != null)
                        {
                            DataGridRow row = rowTracker.Container;
                            DataGridCellsPresenter cellsPresenter = row.CellsPresenter;
                            if (cellsPresenter != null)
                            {
                                ContainerTracking<DataGridCell> cellTracker = cellsPresenter.CellTrackingRoot;
                                while (cellTracker != null)
                                {
                                    DataGridCell cell = cellTracker.Container;
                                    DataGridCellInfo cellInfo = new DataGridCellInfo(cell);
                                    if (cells.Contains(cellInfo))
                                    {
                                        cell.SyncIsSelected(isSelected);
                                    }

                                    cellTracker = cellTracker.Next;
                                }
                            }

                            rowTracker = rowTracker.Next;
                        }
                    }
                    else
                    {
                        foreach (DataGridCellInfo cellInfo in cells)
                        {
                            DataGridCell cell = TryFindCell(cellInfo);
                            if (cell != null)
                            {
                                cell.SyncIsSelected(isSelected);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
 internal bool EqualsImpl(DataGridCellInfo cell)
 {
     return (cell._column == _column) && (cell.Owner == Owner) && (cell._info == _info);
 }
Exemplo n.º 27
0
        /// <summary>
        ///     Processes selection for a row.
        ///     Depending on the current keyboard state, this may mean
        ///     - Selecting the row
        ///     - Deselecting the row
        ///     - Deselecting other rows
        ///     - Extending selection to the row
        /// </summary>
        /// <remarks>
        ///     ADO.Net has a bug (#524977) where if the row is in edit mode
        ///     and atleast one of the cells are edited and committed without
        ///     commiting the row itself, DataView.IndexOf for that row returns -1
        ///     and DataView.Contains returns false. The Workaround to this problem
        ///     is to try to use the previously computed row index if the operations
        ///     are in the same row scope.
        /// </remarks>
        private void MakeFullRowSelection(ItemInfo info, bool allowsExtendSelect, bool allowsMinimalSelect)
        {
            bool extendSelection = allowsExtendSelect && ShouldExtendSelection;

            // minimalModify means that previous selections should not be cleared
            // or that the particular item should be toggled.
            bool minimalModify = allowsMinimalSelect && ShouldMinimallyModifySelection;

            using (UpdateSelectedCells())
            {
                bool alreadyUpdating = IsUpdatingSelectedItems;
                if (!alreadyUpdating)
                {
                    BeginUpdateSelectedItems();
                }

                try
                {
                    if (extendSelection)
                    {
                        // Extend selection from the anchor to the item
                        int numColumns = _columns.Count;
                        if (numColumns > 0)
                        {
                            int startIndex = _selectionAnchor.Value.ItemInfo.Index;
                            int endIndex = info.Index;
                            if (startIndex > endIndex)
                            {
                                // Ensure that startIndex is before endIndex
                                int temp = startIndex;
                                startIndex = endIndex;
                                endIndex = temp;
                            }

                            if ((startIndex >= 0) && (endIndex >= 0))
                            {
                                int numItemsSelected = _selectedItems.Count;

                                if (!minimalModify)
                                {
                                    bool clearedCells = false;

                                    // Unselect items not within the selection range
                                    for (int index = 0; index < numItemsSelected; index++)
                                    {
                                        ItemInfo itemInfo = _selectedItems[index];
                                        int itemIndex = itemInfo.Index;

                                        if ((itemIndex < startIndex) || (endIndex < itemIndex))
                                        {
                                            // Selector has been signaled to delay updating the
                                            // collection until we have finished the entire update.
                                            // The item will actually remain in the collection
                                            // until EndUpdateSelectedItems.
                                            SelectionChange.Unselect(itemInfo);

                                            if (!clearedCells)
                                            {
                                                // We only want to clear if something is actually being removed.
                                                _selectedCells.Clear();
                                                clearedCells = true;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    // If we hold Control key - unselect only the previous drag selection (between CurrentCell and endIndex)
                                    int currentCellIndex = CurrentCell.ItemInfo.Index;
                                    int removeRangeStartIndex = -1;
                                    int removeRangeEndIndex = -1;
                                    if (currentCellIndex < startIndex)
                                    {
                                        removeRangeStartIndex = currentCellIndex;
                                        removeRangeEndIndex = startIndex - 1;
                                    }
                                    else if (currentCellIndex > endIndex)
                                    {
                                        removeRangeStartIndex = endIndex + 1;
                                        removeRangeEndIndex = currentCellIndex;
                                    }

                                    if (removeRangeStartIndex >= 0 && removeRangeEndIndex >= 0)
                                    {
                                        for (int index = 0; index < numItemsSelected; index++)
                                        {
                                            ItemInfo itemInfo = _selectedItems[index];
                                            int itemIndex = itemInfo.Index;

                                            if ((removeRangeStartIndex <= itemIndex) && (itemIndex <= removeRangeEndIndex))
                                            {
                                                // Selector has been signaled to delay updating the
                                                // collection until we have finished the entire update.
                                                // The item will actually remain in the collection
                                                // until EndUpdateSelectedItems.
                                                SelectionChange.Unselect(itemInfo);
                                            }
                                        }

                                        _selectedCells.RemoveRegion(removeRangeStartIndex, 0, removeRangeEndIndex - removeRangeStartIndex + 1, Columns.Count);
                                    }
                                }

                                // Select the children in the selection range
                                IEnumerator enumerator = ((IEnumerable)Items).GetEnumerator();
                                for (int index = 0; index <= endIndex; index++)
                                {
                                    if (!enumerator.MoveNext())
                                    {
                                        // In case the enumerator ends unexpectedly
                                        break;
                                    }

                                    if (index >= startIndex)
                                    {
                                        SelectionChange.Select(ItemInfoFromIndex(index), true);
                                    }
                                }

                                IDisposable d = enumerator as IDisposable;
                                if (d != null)
                                {
                                    d.Dispose();
                                }

                                _selectedCells.AddRegion(startIndex, 0, endIndex - startIndex + 1, _columns.Count);
                            }
                        }
                    }
                    else
                    {
                        if (minimalModify && _selectedItems.Contains(info))
                        {
                            // Unselect the one item
                            UnselectItem(info);
                        }
                        else
                        {
                            if (!minimalModify || !CanSelectMultipleItems)
                            {
                                // Unselect the other items
                                if (_selectedCells.Count > 0)
                                {
                                    // Pre-emptively clear the SelectedCells collection, which is O(1),
                                    // instead of waiting for the selection change notification to clear
                                    // SelectedCells row by row, which is O(n).
                                    _selectedCells.Clear();
                                }

                                if (SelectedItems.Count > 0)
                                {
                                    SelectedItems.Clear();
                                }
                            }

                            if (_editingRowInfo == info)
                            {
                                // ADO.Net bug workaround, see remarks.
                                int numColumns = _columns.Count;
                                if (numColumns > 0)
                                {
                                    _selectedCells.AddRegion(_editingRowInfo.Index, 0, 1, numColumns);
                                }

                                SelectItem(info, false);
                            }
                            else
                            {
                                // Select the item
                                SelectItem(info);
                            }
                        }

                        _selectionAnchor = new DataGridCellInfo(info.Clone(), ColumnFromDisplayIndex(0), this);
                    }
                }
                finally
                {
                    if (!alreadyUpdating)
                    {
                        EndUpdateSelectedItems();
                    }
                }
            }
        }
 private void SetStringToCell(DataGridCellInfo dg, String s)
 {
     TextBlock tb = dg.Column.GetCellContent(dg.Item) as TextBlock;
     tb.Text = s;
 }
Exemplo n.º 29
0
 internal DataGridCell TryFindCell(DataGridCellInfo info)
 {
     // Does not de-virtualize cells
     return TryFindCell(LeaseItemInfo(info.ItemInfo), info.Column);
 }
 // Token: 0x06004732 RID: 18226 RVA: 0x00142714 File Offset: 0x00140914
 internal bool EqualsImpl(DataGridCellInfo cell)
 {
     return(cell._column == this._column && cell.Owner == this.Owner && cell._info == this._info);
 }
Exemplo n.º 31
0
 /// <summary>
 ///     Used to create a copy of an existing DataGridCellInfo, with its own
 ///     ItemInfo (to avoid aliasing).
 /// </summary>
 internal DataGridCellInfo(DataGridCellInfo info)
 {
     _info = info._info.Clone();
     _column = info._column;
     _owner = info._owner;
 }
Exemplo n.º 32
0
 void CurrentCellWindow_Loaded(object sender, RoutedEventArgs e)
 {
     DataGridCellInfo cInfo = new DataGridCellInfo(dgTest, dgTest.Columns[3]);
     dgTest.CurrentCell = cInfo;
 }
        // Private helper returning the automation peer coresponding to cellInfo
        // Cell can be virtualized
        private DataGridCellItemAutomationPeer GetCellItemPeer(DataGridCellInfo cellInfo)
        {
            if (cellInfo.IsValid)
            {
                DataGridItemAutomationPeer dataGridItemAutomationPeer = FindOrCreateItemAutomationPeer(cellInfo.Item) as DataGridItemAutomationPeer;
                if (dataGridItemAutomationPeer != null)
                {
                    return dataGridItemAutomationPeer.GetOrCreateCellItemPeer(cellInfo.Column);
                }
            }

            return null;
        }
 private string GetStringFromCell(DataGridCellInfo dg)
 {
     TextBlock tb = dg.Column.GetCellContent(dg.Item) as TextBlock;
     return tb.Text;
 }