Ejemplo n.º 1
0
        /// <summary>
        /// Fired when a cell receive the focus
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnCellGotFocus(ChangeActivePositionEventArgs e)
        {
            //Check if the position is valid (this is an useful check because there are cases when the rows are changed inside the leaving events, for example on the DataGrid extension when adding new rows), so I check if the row is still valid
            if (Grid.CompleteRange.Contains(e.NewFocusPosition) == false)
            {
                e.Cancel = true;
            }

            if (e.Cancel)
            {
                return;
            }

            //Evento Got Focus
            if (CellGotFocus != null)
            {
                CellGotFocus(this, e);
            }
            if (e.Cancel)
            {
                return;
            }

            //N.B. E' importante impostare prima la variabile m_FocusCell e dopo chiamare l'evento OnEnter, altrimenti nel caso in cui la cella sia impostata in edit sul focus, l'eseguzione va in loop (cerca di fare l'edit ma per far questo è necessario avere il focus ...)
            m_ActivePosition = e.NewFocusPosition;             //Set the focus on the cell

            //Select the cell
            SelectCell(m_ActivePosition, true);

            //Invalidate the selection
            Invalidate();

            ////Recalculate the rectangle border
            //RecalcBorderRange();

            // AlanP: Oct 2013  Some finance screens use the events below.  This ensures we do not get an event cascade.
            if (m_SuppressSelectionChangedEvent)
            {
                return;
            }

            //Cell Focus Entered
            Grid.Controller.OnFocusEntered(new CellContext(Grid, e.NewFocusPosition), EventArgs.Empty);

            //Column/Row Focus Enter
            //If the row is different from the previous row, fire a row focus entered
            if (e.NewFocusPosition.Row != e.OldFocusPosition.Row)
            {
                OnFocusRowEntered(new RowEventArgs(ActivePosition.Row));
            }
            //If the column is different from the previous column, fire a column focus entered
            if (e.NewFocusPosition.Column != e.OldFocusPosition.Column)
            {
                OnFocusColumnEntered(new ColumnEventArgs(ActivePosition.Column));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ASender">sender</param>
        /// <param name="AEventArgs">event</param>
        protected void GrdColumns_CellLostFocus(SelectionBase ASender, ChangeActivePositionEventArgs AEventArgs)
        {
            System.Int32 newcolumn;
            newcolumn         = AEventArgs.NewFocusPosition.Column;
            AEventArgs.Cancel = false;

            if ((FSelectedColumn != -1) && (newcolumn != -1) && (newcolumn != FSelectedColumn) && (!SelectColumn(-1)))
            {
                AEventArgs.Cancel = true;
            }
        }
Ejemplo n.º 3
0
 private void ArtCellGotFocus(SelectionBase sender, ChangeActivePositionEventArgs e)
 {
     _needLoadArt = false;
     _artPosition = e.NewFocusPosition;
     _selectedArt = _artDtos[_artPosition.Row - 1];
     lArt.Text    = _selectedArt.FullName;
     if (_searchMode && !_searchChanging)
     {
         _searchString = "";
         lInfo.Text    = $"Поиск: {_searchString}";
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Select the new column.
        /// </summary>
        /// <param name="ASender">sender</param>
        /// <param name="AEventArgs">event</param>
        protected void GrdColumns_CellGotFocus(SelectionBase ASender, ChangeActivePositionEventArgs AEventArgs)
        {
            System.Int32 newcolumn;

            if (FDuringApplyOrCancel == true)
            {
                grdColumns.Selection.ResetSelection(false);
                return;
            }

            newcolumn         = AEventArgs.NewFocusPosition.Column;
            AEventArgs.Cancel = false;

            if ((FSelectedColumn != -1) && (newcolumn != -1) && (newcolumn != FSelectedColumn) && (!SelectColumn(-1)))
            {
                AEventArgs.Cancel = true;
                grdColumns.Selection.SelectColumn(FSelectedColumn, true);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fired when a cell lost the focus
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnCellLostFocus(ChangeActivePositionEventArgs e)
        {
            if (e.Cancel)
                return;

            //This code is not necessary because when the cell receive a focus I check
            // if the grid can receive the focus using the SetFocusOnCells method.
            // The SetFocusOnCells method cause any editor to automatically close itself.
            // If I leave this code there are problem when the cell lost the focus because the entire grid lost the focus,
            // in this case the EndEdit cause the grid to receive again the focus. (this problem is expecially visible when using the grid inside a tab and you click on the second tab after set an invalid cell value inside the first tab)
            //CellContext cellLostContext = new CellContext(Grid, e.OldFocusPosition);
            ////Stop the Edit operation
            //if (cellLostContext.EndEdit(false) == false)
            //    e.Cancel = true;
            //if (e.Cancel)
            //    return;

            //evento Lost Focus
            if (CellLostFocus != null)
                CellLostFocus(this, e);
            if (e.Cancel)
                return;

            //Row/Column leaving
            //If the new Row is different from the current focus row calls a Row Leaving event
            int focusRow = ActivePosition.Row;
            if (ActivePosition.IsEmpty() == false && focusRow != e.NewFocusPosition.Row)
            {
                RowCancelEventArgs rowArgs = new RowCancelEventArgs(focusRow);
                OnFocusRowLeaving(rowArgs);
                if (rowArgs.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }
            //If the new Row is different from the current focus row calls a Row Leaving event
            int focusColumn = ActivePosition.Column;
            if (ActivePosition.IsEmpty() == false && focusColumn != e.NewFocusPosition.Column)
            {
                ColumnCancelEventArgs columnArgs = new ColumnCancelEventArgs(focusColumn);
                OnFocusColumnLeaving(columnArgs);
                if (columnArgs.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }

            //Change the focus cell to Empty
            m_ActivePosition = Position.Empty; //from now the cell doesn't have the focus

            //Cell Focus Left
            Grid.Controller.OnFocusLeft(new CellContext(Grid, e.OldFocusPosition), EventArgs.Empty);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fired when a cell receive the focus
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnCellGotFocus(ChangeActivePositionEventArgs e)
        {
            //Check if the position is valid (this is an useful check because there are cases when the rows are changed inside the leaving events, for example on the DataGrid extension when adding new rows), so I check if the row is still valid
            if (Grid.CompleteRange.Contains(e.NewFocusPosition) == false)
                e.Cancel = true;

            if (e.Cancel)
                return;

            //Evento Got Focus
            if (CellGotFocus != null)
                CellGotFocus(this, e);
            if (e.Cancel)
                return;

            //N.B. E' importante impostare prima la variabile m_FocusCell e dopo chiamare l'evento OnEnter, altrimenti nel caso in cui la cella sia impostata in edit sul focus, l'eseguzione va in loop (cerca di fare l'edit ma per far questo è necessario avere il focus ...)
            m_ActivePosition = e.NewFocusPosition; //Set the focus on the cell

            //Select the cell
            SelectCell(m_ActivePosition, true);

            //Invalidate the selection
            Invalidate();

            ////Recalculate the rectangle border
            //RecalcBorderRange();

            //Cell Focus Entered
            Grid.Controller.OnFocusEntered(new CellContext(Grid, e.NewFocusPosition), EventArgs.Empty);

            //Column/Row Focus Enter
            //If the row is different from the previous row, fire a row focus entered
            if (e.NewFocusPosition.Row != e.OldFocusPosition.Row)
                OnFocusRowEntered(new RowEventArgs(ActivePosition.Row));
            //If the column is different from the previous column, fire a column focus entered
            if (e.NewFocusPosition.Column != e.OldFocusPosition.Column)
                OnFocusColumnEntered(new ColumnEventArgs(ActivePosition.Column));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Change the ActivePosition (focus) of the grid.
        /// </summary>
        /// <param name="pCellToActivate"></param>
        /// <param name="pResetSelection">True to deselect the previous selected cells</param>
        /// <returns></returns>
        public bool Focus(Position pCellToActivate, bool pResetSelection)
        {
            //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
            bool deselectOtherCells = false;
            if (pCellToActivate.IsEmpty() == false && pResetSelection)
                deselectOtherCells = true;

            pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

            //Check to see if the value is changed (note that I use the internal variable to see the actual stored value)
            if (pCellToActivate != ActivePosition)
            {
                //GotFocus Event Arguments
                Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate);
                CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus);
                ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                if (newCellToFocus != null)
                {
                    //Cell Focus Entering
                    Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
                    if (gotFocusEventArgs.Cancel)
                        return false;

                    //If the cell can't receive the focus stop the focus operation
                    if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
                        return false;
                }

                //If the new cell is valid I check if I can move the focus inside the grid
                if (newCellToFocus != null)
                {
                    //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false.
                    // This is useful for 2 reason:
                    //	-To validate the editor
                    //	-To check if I can move the focus on another cell
                    bool canFocus = Grid.Focus();
                    if (canFocus == false)
                        return false;
                }

                //If there is a cell with the focus fire the focus leave events
                if (IsActivePositionValid())
                {
                    //LostFocus Event Arguments
                    Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition);
                    CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus);
                    ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                    //Cell Focus Leaving
                    Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                        return false;

                    //Cell Lost Focus
                    OnCellLostFocus(lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                        return false;
                }
                else
                {
                    //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells)
                    // NOTE: in this case the focus event are not executed
                    m_ActivePosition = Position.Empty;
                }

                //Deselect previous selected cells
                if (deselectOtherCells)
                    ResetSelection(false);

                bool success;
                if (newCellToFocus != null)
                {
                    //Cell Got Focus
                    OnCellGotFocus(gotFocusEventArgs);

                    success = (!gotFocusEventArgs.Cancel);
                }
                else
                {
                    success = true;
                }

                //Fire a change event
                OnSelectionChanged(EventArgs.Empty);

                return success;
            }
            else
            {
                if (pCellToActivate.IsEmpty() == false)
                {
                    //I check if the grid still has the focus, otherwise I force it
                    if (Grid.ContainsFocus)
                        return true;
                    else
                        return Grid.Focus();
                }
                else
                    return true;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Change the ActivePosition (focus) of the grid.
        /// </summary>
        /// <param name="pCellToActivate"></param>
        /// <param name="pResetSelection">True to deselect the previous selected cells</param>
        /// <returns></returns>
        public bool Focus(Position pCellToActivate, bool pResetSelection)
        {
            //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
            bool deselectOtherCells = false;

            if (pCellToActivate.IsEmpty() == false && pResetSelection)
            {
                deselectOtherCells = true;
            }

            pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

            //Check to see if the value is changed (note that I use the internal variable to see the actual stored value)
            if (pCellToActivate != ActivePosition)
            {
                //GotFocus Event Arguments
                Cells.ICellVirtual            newCellToFocus    = Grid.GetCell(pCellToActivate);
                CellContext                   newCellContext    = new CellContext(Grid, pCellToActivate, newCellToFocus);
                ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                if (newCellToFocus != null)
                {
                    //Cell Focus Entering
                    Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
                    if (gotFocusEventArgs.Cancel)
                    {
                        return(false);
                    }

                    //If the cell can't receive the focus stop the focus operation
                    if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
                    {
                        return(false);
                    }
                }

                //If the new cell is valid I check if I can move the focus inside the grid
                if (newCellToFocus != null)
                {
                    //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false.
                    // This is useful for 2 reason:
                    //	-To validate the editor
                    //	-To check if I can move the focus on another cell
                    bool canFocus = Grid.Focus();
                    if (canFocus == false)
                    {
                        return(false);
                    }
                }

                RangeRegion oldFocusRegion = null;

                //If there is a cell with the focus fire the focus leave events
                if (IsActivePositionValid())
                {
                    oldFocusRegion = new RangeRegion(ActivePosition);

                    //LostFocus Event Arguments
                    Cells.ICellVirtual            oldCellFocus       = Grid.GetCell(ActivePosition);
                    CellContext                   oldCellContext     = new CellContext(Grid, ActivePosition, oldCellFocus);
                    ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                    //Cell Focus Leaving
                    Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }

                    //Cell Lost Focus
                    OnCellLostFocus(lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }
                }
                else
                {
                    //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells)
                    // NOTE: in this case the focus event are not executed
                    m_ActivePosition = Position.Empty;
                }

                //Deselect previous selected cells
                if (deselectOtherCells)
                {
                    ResetSelection(false);
                }

                bool success;
                if (newCellToFocus != null)
                {
                    //Cell Got Focus
                    OnCellGotFocus(gotFocusEventArgs);

                    success = (!gotFocusEventArgs.Cancel);
                }
                else
                {
                    success = true;
                }

                //Fire a change event
                RangeRegion newFocusRegion = new RangeRegion(pCellToActivate);
                OnSelectionChanged(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion));

                return(success);
            }
            else
            {
                if (pCellToActivate.IsEmpty() == false)
                {
                    //I check if the grid still has the focus, otherwise I force it
                    if (Grid.ContainsFocus)
                    {
                        return(true);
                    }
                    else
                    {
                        return(Grid.Focus());
                    }
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Fired when a cell lost the focus
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnCellLostFocus(ChangeActivePositionEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }

            //This code is not necessary because when the cell receive a focus I check
            // if the grid can receive the focus using the SetFocusOnCells method.
            // The SetFocusOnCells method cause any editor to automatically close itself.
            // If I leave this code there are problem when the cell lost the focus because the entire grid lost the focus,
            // in this case the EndEdit cause the grid to receive again the focus. (this problem is expecially visible when using the grid inside a tab and you click on the second tab after set an invalid cell value inside the first tab)
            //CellContext cellLostContext = new CellContext(Grid, e.OldFocusPosition);
            ////Stop the Edit operation
            //if (cellLostContext.EndEdit(false) == false)
            //    e.Cancel = true;
            //if (e.Cancel)
            //    return;

            //evento Lost Focus
            if (CellLostFocus != null)
            {
                CellLostFocus(this, e);
            }
            if (e.Cancel)
            {
                return;
            }

            //Row/Column leaving
            //If the new Row is different from the current focus row calls a Row Leaving event
            int focusRow = ActivePosition.Row;

            if (ActivePosition.IsEmpty() == false && focusRow != e.NewFocusPosition.Row)
            {
                RowCancelEventArgs rowArgs = new RowCancelEventArgs(focusRow);
                OnFocusRowLeaving(rowArgs);
                if (rowArgs.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }
            //If the new Row is different from the current focus row calls a Row Leaving event
            int focusColumn = ActivePosition.Column;

            if (ActivePosition.IsEmpty() == false && focusColumn != e.NewFocusPosition.Column)
            {
                ColumnCancelEventArgs columnArgs = new ColumnCancelEventArgs(focusColumn);
                OnFocusColumnLeaving(columnArgs);
                if (columnArgs.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
            }

            //Change the focus cell to Empty
            m_ActivePosition = Position.Empty; //from now the cell doesn't have the focus

            //Cell Focus Left
            Grid.Controller.OnFocusLeft(new CellContext(Grid, e.OldFocusPosition), EventArgs.Empty);
        }
Ejemplo n.º 10
0
		// AlanP: Sep 2013  Added an optional parameter to specify that selection_changed events should be suppressed
        /// <summary>
		/// Change the ActivePosition (focus) of the grid.
		/// </summary>
		/// <param name="pCellToActivate"></param>
		/// <param name="pResetSelection">True to deselect the previous selected cells</param>
        /// <param name="suppressChangeEvent">Set to true to suppress Selection_Changed events</param>
		/// <returns></returns>
		public bool Focus(Position pCellToActivate, bool pResetSelection, bool suppressChangeEvent = false)
		{
			//If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
			bool deselectOtherCells = false;
			if (pCellToActivate.IsEmpty() == false && pResetSelection)
				deselectOtherCells = true;

			//pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

			//Check to see if the value is changed (note that I use the internal variable to see the actual stored value)
			if (pCellToActivate != ActivePosition)
			{
				//GotFocus Event Arguments
				Cells.ICellVirtual newCellToFocus = Grid.GetCell(pCellToActivate);
				CellContext newCellContext = new CellContext(Grid, pCellToActivate, newCellToFocus);
				ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

				if (newCellToFocus != null)
				{
					//Cell Focus Entering
					Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
					if (gotFocusEventArgs.Cancel)
						return false;

					//If the cell can't receive the focus stop the focus operation
					if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
						return false;
				}

				//If the new cell is valid I check if I can move the focus inside the grid
				if (newCellToFocus != null)
				{
					//This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false.
					// This is useful for 2 reason:
					//	-To validate the editor
					//	-To check if I can move the focus on another cell
					bool canFocus = Grid.Focus(false);
                    if (canFocus == false)
                    {
                        // AlanP: Oct 2013
                        // The grid cannot be focused, which happens when we call SelectRowInGrid before the screen has been 'activated'.
                        // We still want to fire our SelectionChanged event
                        ResetSelection(false, true);
                        SelectCell(pCellToActivate, true);
                        return false;
                    }
				}

				RangeRegion oldFocusRegion = null;

				//If there is a cell with the focus fire the focus leave events
				if (IsActivePositionValid())
				{
					oldFocusRegion = new RangeRegion(ActivePosition);

					//LostFocus Event Arguments
					Cells.ICellVirtual oldCellFocus = Grid.GetCell(ActivePosition);
					CellContext oldCellContext = new CellContext(Grid, ActivePosition, oldCellFocus);
					ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

					//Cell Focus Leaving
					Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
					if (lostFocusEventArgs.Cancel)
						return false;

					//Cell Lost Focus
					OnCellLostFocus(lostFocusEventArgs);
					if (lostFocusEventArgs.Cancel)
						return false;
				}
				else
				{
					//Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells)
					// NOTE: in this case the focus event are not executed
					m_ActivePosition = Position.Empty;
				}

				//Deselect previous selected cells
				if (deselectOtherCells)
					ResetSelection(false);

                // AlanP: Sep 2013  set our new member variable
                m_SuppressSelectionChangedEvent = suppressChangeEvent;

                bool success;
				if (newCellToFocus != null)
				{
					//Cell Got Focus
                    // AlanP: this will fire SelectionChanged
					OnCellGotFocus(gotFocusEventArgs);

					success = (!gotFocusEventArgs.Cancel);
				}
				else
				{
                    // AlanP: Sep 2013  Added this because when we are Focussing on an empty grid this is our chance to fire SelectionChanged
                    SelectCell(Position.Empty, true);
					success = true;
				}

				//Fire a change event
                // AlanP: Sept 2013  Changed OnSelectionChanged to new method InvalidateGridSelection
                //  This results in no SelectionChanged event being fired but we still get the grid invalidated
                RangeRegion newFocusRegion = new RangeRegion(pCellToActivate);
                InvalidateGridSelection(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion));

                // AlanP: Sep 2013  Reset the new member variable
                m_SuppressSelectionChangedEvent = false;

                return success;
			}
			else
			{
                // The cell to activate is the same as the active position
                if (pCellToActivate.IsEmpty() == false)
                {
                    DeselectOldRangeAndSelectActiveCell();

                    //I check if the grid still has the focus, otherwise I force it
                    if (Grid.ContainsFocus)
                        return true;
                    else
                        return Grid.Focus();
                }
                else
                {
                    // AlanP Sep 2013
                    // Even though we are activating an empty position when the position is already empty
                    // we will fire off a selectionChanged event because this is useful on an empty grid when the main screen activates for the first time
                    OnSelectionChanged(new RangeRegionChangedEventArgs(Range.Empty, Range.Empty));
                    return true;
                }
			}
		}
Ejemplo n.º 11
0
        // AlanP: Sep 2013  Added an optional parameter to specify that selection_changed events should be suppressed
        /// <summary>
        /// Change the ActivePosition (focus) of the grid.
        /// </summary>
        /// <param name="pCellToActivate"></param>
        /// <param name="pResetSelection">True to deselect the previous selected cells</param>
        /// <param name="suppressChangeEvent">Set to true to suppress Selection_Changed events</param>
        /// <returns></returns>
        public bool Focus(Position pCellToActivate, bool pResetSelection, bool suppressChangeEvent = false)
        {
            //If control key is pressed, enableMultiSelection is true and the cell that will receive the focus is not empty leave the cell selected otherwise deselect other cells
            bool deselectOtherCells = false;

            if (pCellToActivate.IsEmpty() == false && pResetSelection)
            {
                deselectOtherCells = true;
            }

            //pCellToActivate = Grid.PositionToStartPosition(pCellToActivate);

            //Check to see if the value is changed (note that I use the internal variable to see the actual stored value)
            if (pCellToActivate != ActivePosition)
            {
                //GotFocus Event Arguments
                Cells.ICellVirtual            newCellToFocus    = Grid.GetCell(pCellToActivate);
                CellContext                   newCellContext    = new CellContext(Grid, pCellToActivate, newCellToFocus);
                ChangeActivePositionEventArgs gotFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                if (newCellToFocus != null)
                {
                    //Cell Focus Entering
                    Grid.Controller.OnFocusEntering(newCellContext, gotFocusEventArgs);
                    if (gotFocusEventArgs.Cancel)
                    {
                        return(false);
                    }

                    //If the cell can't receive the focus stop the focus operation
                    if (Grid.Controller.CanReceiveFocus(newCellContext, gotFocusEventArgs) == false)
                    {
                        return(false);
                    }
                }

                //If the new cell is valid I check if I can move the focus inside the grid
                if (newCellToFocus != null)
                {
                    //This method cause any cell editor to leave the focus if the validation is ok, otherwise returns false.
                    // This is useful for 2 reason:
                    //	-To validate the editor
                    //	-To check if I can move the focus on another cell
                    bool canFocus = Grid.Focus(false);
                    if (canFocus == false)
                    {
                        // AlanP: Oct 2013
                        // The grid cannot be focused, which happens when we call SelectRowInGrid before the screen has been 'activated'.
                        // We still want to fire our SelectionChanged event
                        ResetSelection(false, true);
                        SelectCell(pCellToActivate, true);
                        return(false);
                    }
                }

                RangeRegion oldFocusRegion = null;

                //If there is a cell with the focus fire the focus leave events
                if (IsActivePositionValid())
                {
                    oldFocusRegion = new RangeRegion(ActivePosition);

                    //LostFocus Event Arguments
                    Cells.ICellVirtual            oldCellFocus       = Grid.GetCell(ActivePosition);
                    CellContext                   oldCellContext     = new CellContext(Grid, ActivePosition, oldCellFocus);
                    ChangeActivePositionEventArgs lostFocusEventArgs = new ChangeActivePositionEventArgs(ActivePosition, pCellToActivate);

                    //Cell Focus Leaving
                    Grid.Controller.OnFocusLeaving(oldCellContext, lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }

                    //Cell Lost Focus
                    OnCellLostFocus(lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }
                }
                else
                {
                    //Reset anyway the actual value. This can happen when there is an ActivePosition but it is not more valid (outside the valid range maybe when removing some cells)
                    // NOTE: in this case the focus event are not executed
                    m_ActivePosition = Position.Empty;
                }

                //Deselect previous selected cells
                if (deselectOtherCells)
                {
                    ResetSelection(false);
                }

                // AlanP: Sep 2013  set our new member variable
                m_SuppressSelectionChangedEvent = suppressChangeEvent;

                bool success;
                if (newCellToFocus != null)
                {
                    //Cell Got Focus
                    // AlanP: this will fire SelectionChanged
                    OnCellGotFocus(gotFocusEventArgs);

                    success = (!gotFocusEventArgs.Cancel);
                }
                else
                {
                    // AlanP: Sep 2013  Added this because when we are Focussing on an empty grid this is our chance to fire SelectionChanged
                    SelectCell(Position.Empty, true);
                    success = true;
                }

                //Fire a change event
                // AlanP: Sept 2013  Changed OnSelectionChanged to new method InvalidateGridSelection
                //  This results in no SelectionChanged event being fired but we still get the grid invalidated
                RangeRegion newFocusRegion = new RangeRegion(pCellToActivate);
                InvalidateGridSelection(new RangeRegionChangedEventArgs(newFocusRegion, oldFocusRegion));

                // AlanP: Sep 2013  Reset the new member variable
                m_SuppressSelectionChangedEvent = false;

                return(success);
            }
            else
            {
                // The cell to activate is the same as the active position
                if (pCellToActivate.IsEmpty() == false)
                {
                    DeselectOldRangeAndSelectActiveCell();

                    //I check if the grid still has the focus, otherwise I force it
                    if (Grid.ContainsFocus)
                    {
                        return(true);
                    }
                    else
                    {
                        return(Grid.Focus());
                    }
                }
                else
                {
                    // AlanP Sep 2013
                    // Even though we are activating an empty position when the position is already empty
                    // we will fire off a selectionChanged event because this is useful on an empty grid when the main screen activates for the first time
                    OnSelectionChanged(new RangeRegionChangedEventArgs(Range.Empty, Range.Empty));
                    return(true);
                }
            }
        }