예제 #1
0
        public bool SetFocusOnSelectedRow(object selected, string columnHeader)
        {
            if ((this.ParentMenu != null && this.ParentMenu.IsOpen) ||
                (this.ContextMenu != null && this.ContextMenu.IsOpen))
            {
                // fix bug where context menu disappears when you right click on a new item.
                return(false);
            }
            // the focus this row so that user can continue using keyboard navigation
            DataGridRow row = this.ItemContainerGenerator.ContainerFromItem(selected) as DataGridRow;

            if (row != null)
            {
                int columnToFocus = GetColumnIndexByTemplateHeader(columnHeader);
                if (columnToFocus < 0)
                {
                    return(false);
                }
                DataGridCellInfo dgci = this.SelectedCells[columnToFocus];
                if (dgci != null)
                {
                    int rowIndex = row.GetIndex();
                    int colIndex = GetColIndex(dgci);
                    row.ApplyTemplate();
                    DataGridCell dgc = GetCell(rowIndex, colIndex);
                    if (dgc != null)
                    {
                        dgc.Focus();
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
 private DataGridCell GetCell(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)
         {
             DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
             if (cell == null)
             {
                 /* bring the column into view
                  * in case it has been virtualized away */
                 ScrollIntoView(rowContainer, Columns[column]);
                 cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
             }
             return(cell);
         }
     }
     return(null);
 }
        static DataGridCell GetCell(DataGrid dataGrid, DataGridRow row, int column)
        {
            if (dataGrid == null)
            {
                throw new ArgumentNullException(nameof(dataGrid));
            }
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(column));
            }

            DataGridCellsPresenter presenter = FindVisualChild <DataGridCellsPresenter>(row);

            if (presenter == null)
            {
                row.ApplyTemplate();
                presenter = FindVisualChild <DataGridCellsPresenter>(row);
            }
            if (presenter != null)
            {
                var cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                if (cell == null)
                {
                    dataGrid.ScrollIntoView(row, dataGrid.Columns[column]);
                    cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                }
                return(cell);
            }
            return(null);
        }
예제 #4
0
        public static void SetFocusOnNewCreatedColumn(DataGrid DataGrid, int rowIndex)
        {
            DataGrid.Focus();

            DataGridRow rowContainer = DataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex) as DataGridRow;

            if (rowContainer == null)
            {
                DataGrid.SelectedIndex = rowIndex;
                DataGrid.ScrollIntoView(DataGrid.SelectedItem);
                rowContainer = DataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex) as DataGridRow;
            }
            if (rowContainer != null)
            {
                rowContainer.ApplyTemplate();
                DataGridCellsPresenter presenter = WpfTools.FindVisualChild <DataGridCellsPresenter>(rowContainer);
                DataGridCell           cell      = presenter.ItemContainerGenerator.ContainerFromIndex(0) as DataGridCell;
                if (cell == null)
                {
                    /* bring the column into view in case it has been virtualized away */
                    DataGrid.ScrollIntoView(rowContainer, DataGrid.Columns[0]);
                    cell = presenter.ItemContainerGenerator.ContainerFromIndex(0) as DataGridCell;
                }
                if (cell != null)
                {
                    cell.Focus();
                }
            }
        }
예제 #5
0
파일: ColorCode.cs 프로젝트: brownj94/Pat
        /// <summary>
        /// Get the cell and its data for decision making
        /// </summary>
        public static DataGridCell GetCell(DataGrid dataGrid, DataGridRow rowContainer, int column)
        {
            if (rowContainer != null)
            {
                //get the childern of the visual presenter
                DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
                if (presenter == null)
                {
                    rowContainer.ApplyTemplate();
                    presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
                }
                if (presenter != null)
                {
                    //get the findal cell object
                    DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    //if the cell object is null refresh grid and get the current cell object
                    if (cell == null)
                    {
                        dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                        dataGrid.UpdateLayout();
                        cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    }

                    return(cell);
                }
            }
            return(null);
        }
예제 #6
0
        public static DataGridCell GetCell(this DataGrid source, int row, int column)
        {
            DataGridRow rowContainer = GetRow(source, row);

            if (rowContainer != null)
            {
                DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
                if (presenter == null)
                {
                    rowContainer.ApplyTemplate();
                    presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
                }

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

                DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                if (cell == null)
                {
                    source.ScrollIntoView(rowContainer, source.Columns[column]);
                    cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                }
                return(cell);
            }
            return(null);
        }
예제 #7
0
        public bool SetFocusOnSelectedRow(object selected, string columnHeader)
        {
            // the focus this row so that user can continue using keyboard navigation
            DataGridRow row = this.ItemContainerGenerator.ContainerFromItem(selected) as DataGridRow;

            if (row != null)
            {
                int columnToFocus = GetColumnIndexByTemplateHeader(columnHeader);
                if (columnToFocus < 0)
                {
                    return(false);
                }
                DataGridCellInfo dgci = this.SelectedCells[columnToFocus];
                if (dgci != null)
                {
                    int rowIndex = row.GetIndex();
                    int colIndex = GetColIndex(dgci);
                    row.ApplyTemplate();
                    DataGridCell dgc = GetCell(rowIndex, colIndex);
                    if (dgc != null)
                    {
                        dgc.Focus();
                        return(true);
                    }
                }
            }
            return(false);
        }
        private static DataGridCell GetCell(DataGrid dataGrid, DataGridRow rowContainer, int column)
        {
            var 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)
                {
                    return(null);
                }
            }

            if (presenter.ItemContainerGenerator.ContainerFromIndex(column) is not DataGridCell cell)
            {
                // Bring the column into view in case it has been virtualized away
                dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
            }

            return(cell);
        }
예제 #9
0
        public static DataGridCell GetCellByItem(DataGrid grid, object item, int column)
        {
            DataGridCell result = null;

            if (item != null && grid != null)
            {
                DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(item);
                if (row == null)
                {
                    grid.UpdateLayout();
                    grid.SelectedItem = item;
                    grid.ScrollIntoView(item);
                    row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(item);
                }
                if (row != null)
                {
                    DataGridCellsPresenter cellPresenter = UISearch.FindVisualChild <DataGridCellsPresenter>(row);
                    if (cellPresenter == null)
                    {
                        row.ApplyTemplate();
                        cellPresenter = UISearch.FindVisualChild <DataGridCellsPresenter>(row);
                    }
                    if (cellPresenter != null)
                    {
                        DataGridCell cell = cellPresenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;

                        if (cell == null)
                        {
                            grid.ScrollIntoView(row, grid.Columns[0]);
                            cell = cellPresenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                        }
                        if (cell != null)
                        {
                            result = cell;
                        }
                    }
                }
            }
            return(result);
        }
예제 #10
0
 public static DataGridCell GetCell(DataGrid dataGrid, DataGridRow rowContainer, int column)
 {
     if (rowContainer != null)
     {
         DataGridCellsPresenter presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
         if (presenter == null)
         {
             rowContainer.ApplyTemplate();
             presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
         }
         if (presenter != null)
         {
             DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
             if (cell == null)
             {
                 dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                 cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
             }
             return(cell);
         }
     }
     return(null);
 }
        /// <summary>
        /// 指定した行、列のセルを取得
        /// </summary>
        /// <param name="grid">取得対象DataGrid</param>
        /// <param name="row">行</param>
        /// <param name="column">列番号</param>
        /// <returns>セル</returns>
        private static DataGridCell?GetCell(DataGrid grid, DataGridRow row, int column)
        {
            if (row != null)
            {
                var presenter = FindVisualChild <DataGridCellsPresenter>(row);
                if (presenter == null)
                {
                    row.ApplyTemplate();
                    presenter = FindVisualChild <DataGridCellsPresenter>(row);
                }
                if (presenter != null)
                {
                    var cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    if (cell != null)
                    {
                        grid.ScrollIntoView(row, grid.Columns[column]);
                        cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    }
                    return(cell);
                }
            }

            return(null);
        }