GetCell() public method

Return the Cell at the specified Row and Col position.
public GetCell ( int p_iRow, int p_iCol ) : Cells.ICellVirtual
p_iRow int
p_iCol int
return Cells.ICellVirtual
		public void GetCell_OutOfBounds()
		{
			Grid grid = new Grid();
			grid.Redim(5, 5);
			
			Assert.AreEqual(null, grid.GetCell(new Position(10, 10)));
		}
		public void GetCell_NonExistent()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			Assert.AreEqual(null, grid1.GetCell(0, 0));
		}
		public void GetCell()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			Cell visibleCell = new SourceGrid.Cells.Cell("Text Span", typeof(string));
			
			// this cell should span both to the right, and to the left
			grid1[0, 0] = visibleCell;
			grid1[0, 0].RowSpan = 2;
			grid1[0, 0].ColumnSpan = 2;
			
			
			Assert.AreEqual(visibleCell, grid1.GetCell(0, 0));
			Assert.AreEqual(visibleCell, grid1.GetCell(0, 1));
			Assert.AreEqual(visibleCell, grid1.GetCell(1, 0));
			Assert.AreEqual(visibleCell, grid1.GetCell(1, 1));
		}
		public void AreSpannedCells_CorrectlyRemoved()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			grid1[0, 0] = new Cell();
			grid1[0, 0].ColumnSpan = 2;
			grid1[0, 0] = null;
			
			// this should be true. But is not, at the moment of writing
			Assert.AreEqual(null, grid1.GetCell(0, 1));
			// this should not throw exception
			grid1[0, 1] = new Cell("my new cell");
		}
示例#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 RecalcBorderRange()
        {
            if (IsEmpty())
            {
                mRangeHighlight.Range = Range.Empty;
            }
            else
            {
                if (BorderMode == SelectionBorderMode.FocusCell)
                {
                    if (m_ActivePosition.IsEmpty() == false)
                    {
                        mRangeHighlight.Range = Grid.PositionToCellRange(m_ActivePosition);
                    }
                    else
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
                else if (BorderMode == SelectionBorderMode.FocusRange)
                {
                    RangeCollection selectedRanges = GetRanges();
                    for (int i = 0; i < selectedRanges.Count; i++)
                    {
                        Range range = selectedRanges[i];
                        if (range.Contains(m_ActivePosition))
                        {
                            mRangeHighlight.Range = range;
                            return;
                        }
                    }
                    mRangeHighlight.Range = Range.Empty;
                }
                else if (BorderMode == SelectionBorderMode.UniqueRange)
                {
                    RangeCollection selectedRanges = GetRanges();
                    if (selectedRanges.Count == 1)
                    {
                        mRangeHighlight.Range = selectedRanges[0];
                    }
                    else
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
                else if (BorderMode == SelectionBorderMode.Auto)
                {
                    RangeCollection selectedRanges = GetRanges();
                    if (selectedRanges.Count == 1)
                    {
                        mRangeHighlight.Range = selectedRanges[0];
                    }
                    else if (m_ActivePosition.IsEmpty() == false)
                    {
                        mRangeHighlight.Range = Grid.PositionToCellRange(m_ActivePosition);
                    }
                    else
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
                else
                {
                    mRangeHighlight.Range = Range.Empty;
                }

                //Set if the selected cells have the OwnerDrawSelectionBorder enabled.
                if (mRangeHighlight.Range.ColumnsCount == 1 && mRangeHighlight.Range.RowsCount == 1)
                {
                    SourceGrid.Cells.ICellVirtual cell = Grid.GetCell(mRangeHighlight.Range.Start);
                    if (cell != null && cell.View.OwnerDrawSelectionBorder)
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Draw the selection using the SelectionColor property over the selected cells. Draw a Border around the selection using Border and BorderMode properties.
        /// </summary>
        /// <param name="p_Panel"></param>
        /// <param name="graphics"></param>
        /// <param name="pRangeToRedraw">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param>
        public virtual void DrawSelectionMask(GridSubPanel p_Panel, DevAge.Drawing.GraphicsCache graphics, Range pRangeToRedraw)
        {
            if (IsEmpty())
            {
                return;
            }

            Region     oldClip       = graphics.Graphics.Clip;
            SolidBrush brushFillMask = graphics.BrushsCache.GetBrush(BackColor);

            try
            {
                graphics.Graphics.Clip = new Region(graphics.ClipRectangle);

                Range     rangeFocus = Range.Empty;
                Rectangle rectFocus  = Rectangle.Empty;
                if (m_ActivePosition.IsEmpty() == false && pRangeToRedraw.Contains(m_ActivePosition))
                {
                    rectFocus  = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(m_ActivePosition));
                    rangeFocus = Grid.PositionToCellRange(m_ActivePosition);
                }
                Cells.ICellVirtual cellFocus = Grid.GetCell(m_ActivePosition);

                //Draw selection mask and border
                //Draw each cell separately
                if ((m_MaskStyle & SelectionMaskStyle.DrawOnlyInitializedCells) == SelectionMaskStyle.DrawOnlyInitializedCells &&
                    (MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)                      //Draw Over cells enabled?
                {
                    PositionCollection selectedCells = GetCellsPositions();
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        //if must be redrawed, is is not the cell with the focus and contains a cell
                        if (pRangeToRedraw.Contains(selectedCells[i]) && rangeFocus.Contains(selectedCells[i]) == false &&
                            Grid.GetCell(selectedCells[i]) != null)
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(selectedCells[i]));
                            graphics.Graphics.FillRectangle(brushFillMask, rect);
                        }
                    }
                }
                //draw all the selected ranges (Default) //Draw Over cells enabled?
                else if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                {
                    RangeCollection selectedRanges = GetRanges();
                    for (int i = 0; i < selectedRanges.Count; i++)
                    {
                        Range range = selectedRanges[i];
                        if (range.IntersectsWith(pRangeToRedraw))
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.RangeToRectangle(range));

                            if (range.Contains(m_ActivePosition))
                            {
                                Region region = new Region(rect);
                                region.Exclude(rectFocus);
                                graphics.Graphics.FillRegion(brushFillMask, region);
                            }
                            else
                            {
                                graphics.Graphics.FillRectangle(brushFillMask, rect);
                            }
                        }
                    }
                }

                //Draw focus mask and focus border (only if there is a fucus cell and is not in editng mode)
                CellContext focusCellContext = new CellContext(Grid, m_ActivePosition, cellFocus);
                if (cellFocus != null && focusCellContext.IsEditing() == false &&
                    pRangeToRedraw.Contains(m_ActivePosition))
                {
                    //Draw Over cells enabled?
                    if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                    {
                        if (m_FocusBackColor != Color.Transparent)
                        {
                            Brush focusBrush = graphics.BrushsCache.GetBrush(m_FocusBackColor);
                            graphics.Graphics.FillRectangle(focusBrush, rectFocus);
                        }
                    }
                }

                if (focusCellContext.IsEditing() == false)
                {
                    mRangeHighlight.DrawHighlight(p_Panel, graphics, pRangeToRedraw);
                }
            }
            finally
            {
                graphics.Graphics.Clip = oldClip;
            }
        }