Cell Lost Focus event arguments with the old position and the new position. Extends PositionCancelEventArgs.
상속: System.ComponentModel.CancelEventArgs
예제 #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
            Add(m_ActivePosition);

            //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));
            }
        }
        /// <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);
            }
        }
        /// <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;
            }
        }
예제 #4
0
        /// <summary>
        /// Fired when a cell lost the focus
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnCellLostFocus(ChangeActivePositionEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }

            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);
        }
예제 #5
0
        /// <summary>
        /// Change the focus of the grid.
        /// The calls order is:
        ///
        /// (the user select CellX)
        /// CellX.FocusEntering
        /// Grid.CellGotFocus(CellX),
        /// CellX.FocusEntered,
        /// [OnFocusRowEntered],
        /// [OnFocusColumnEntered]
        ///
        /// (the user select CellY),
        /// CellY.FocusEntering
        /// CellX.FocusLeaving
        /// Grid.CellLostFocus(CellX),
        /// [OnFocusRowLeaving],
        /// [OnFocusColumnLeaving],
        /// CellX.FocusLeft,
        /// Grid.CellGotFocus(CellY),
        /// CellY.FocusEntered,
        /// [OnFocusRowEntered],
        /// [OnFocusColumnEntered]
        ///
        /// Use Position.Empty to remove the focus cell.
        /// </summary>
        /// <param name="pCellToActivate"></param>
        /// <param name="pResetSelection">Reset the other selected cells.</param>
        /// <returns></returns>
        public virtual 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);

            //Questo controllo è necessario altrimenti l'evento verrebbe scatenato due volte per la stessa cella
            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);

                //LostFocus Event Arguments
                Cells.ICellVirtual            oldCellFocus       = Grid.GetCell(ActivePosition);
                CellContext                   oldCellContext     = new CellContext(Grid, ActivePosition, oldCellFocus);
                ChangeActivePositionEventArgs lostFocusEventArgs = 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 focus is already insede the grid (bug maybe in another control) or the new cell is valid
                if (Grid.ContainsFocus || 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.SetFocusOnCells(true);
                    if (canFocus == false)
                    {
                        return(false);
                    }
                }


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

                    //Cell Lost Focus
                    OnCellLostFocus(lostFocusEventArgs);
                    if (lostFocusEventArgs.Cancel)
                    {
                        return(false);
                    }
                }

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

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

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

                return(success);
            }
            else
            {
                return(true);
            }
        }
예제 #6
0
 private void _grid_Selection_CellGotFocus(SourceGrid.Selection.SelectionBase sender, SourceGrid.ChangeActivePositionEventArgs e)
 {
     try {
     } catch (Exception error) {
         ExceptionDialog.Show(this, error);
     }
 }