static Microsoft.Windows.Controls.DataGridCell TryToFindGridCell(Microsoft.Windows.Controls.DataGrid grid, Microsoft.Windows.Controls.DataGridCellInfo cellInfo)
 {
     Microsoft.Windows.Controls.DataGridCell result = null;
     Microsoft.Windows.Controls.DataGridRow  row    = null;
     try
     {
         grid.ScrollIntoView(cellInfo.Item);
         grid.UpdateLayout();
         row = (Microsoft.Windows.Controls.DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(cellInfo.Item);
         if (row != null)
         {
             int columnIndex = grid.Columns.IndexOf(cellInfo.Column);
             if (columnIndex > -1)
             {
                 Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter presenter = GetVisualChild <Microsoft.Windows.Controls.Primitives.DataGridCellsPresenter>(row);
                 result = presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex) as Microsoft.Windows.Controls.DataGridCell;
             }
         }
     }
     catch (Exception generalException)
     {
         string error = generalException.Message;
         result = null;
     }
     return(result);
 }
示例#2
0
 public static Microsoft.Windows.Controls.DataGridCell GetCell(Microsoft.Windows.Controls.DataGrid dataGrid, Microsoft.Windows.Controls.DataGridRow rowContainer, int column)
 {
     if (rowContainer != null)
     {
         DataGridCellsPresenter presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
         if (presenter == null)
         {
             /* if the row has been virtualized away, call its ApplyTemplate() method
              * to build its visual tree in order for the DataGridCellsPresenter
              * and the DataGridCells to be created */
             rowContainer.ApplyTemplate();
             presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
         }
         if (presenter != null)
         {
             Microsoft.Windows.Controls.DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as Microsoft.Windows.Controls.DataGridCell;
             if (cell == null)
             {
                 /* bring the column into view
                  * in case it has been virtualized away */
                 dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                 cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as Microsoft.Windows.Controls.DataGridCell;
             }
             return(cell);
         }
     }
     return(null);
 }
示例#3
0
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="row">The row.</param>
        /// <param name="columnIndex">Index of the column.</param>
        /// <returns></returns>
        public static Microsoft.Windows.Controls.DataGridCell GetCell(Microsoft.Windows.Controls.DataGrid host, Microsoft.Windows.Controls.DataGridRow row, int columnIndex)
        {
            if (row == null)
            {
                return(null);
            }

            var presenter = GetVisualChild <DataGridCellsPresenter>(row);

            if (presenter == null)
            {
                return(null);
            }

            // try to get the cell but it may possibly be virtualized
            var cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);

            if (cell == null)
            {
                // now try to bring into view and retreive the cell
                host.ScrollIntoView(row, host.Columns[columnIndex]);
                cell = (Microsoft.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
            }
            return(cell);
        }
示例#4
0
        //When selection changed in combobox (pressing  arrow key down or up) must be synchronized with opened Microsoft.Windows.Controls.DataGrid popup
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);
            if (popupDataGrid == null)
            {
                return;
            }

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                if (IsDropDownOpen)
                {
                    popupDataGrid.SelectedItem = this.SelectedItem;
                    if (popupDataGrid.SelectedItem != null)
                    {
                        popupDataGrid.ScrollIntoView(popupDataGrid.SelectedItem);
                    }
                }
            }
        }