SourceGrid.GridVirtual.GetScrollPositionToShowCell C# (CSharp) Method

GetScrollPositionToShowCell() protected method

Indicates if the specified range is visible Return the scroll position that must be set to show a specific cell.
protected GetScrollPositionToShowCell ( Position position, bool partial, Point &newScrollPosition ) : bool
position Position
partial bool True to return also partial visible cells
newScrollPosition Point
return bool
        protected virtual bool GetScrollPositionToShowCell(Position position, bool partial, out Point newScrollPosition)
        {
            Rectangle displayRectangle = DisplayRectangle;

            List<int> rows = GetVisibleRows(partial);
            List<int> columns = GetVisibleColumns(partial);

            if (rows.Contains(position.Row) && columns.Contains(position.Column))
            {
                newScrollPosition = CustomScrollPosition;
                return false;
            }
            else
            {
                CellPositionType posType = GetPositionType(position);
                bool isFixedTop = false;
                if (posType == CellPositionType.FixedTop || posType == CellPositionType.FixedTopLeft)
                    isFixedTop = true;
                bool isFixedLeft = false;
                if (posType == CellPositionType.FixedLeft || posType == CellPositionType.FixedTopLeft)
                    isFixedLeft = true;

                int x;
                if (columns.Contains(position.Column)) //Is x visible
                {
                    x = CustomScrollPosition.X;
                }
                else
                {
                    if (isFixedLeft)
                        x = 0;
                    else
                        x = position.Column - FixedColumns;

                    //Check if the scrollable positioin if not outside the valid area
                    int maxX = GetScrollColumns(displayRectangle.Width);
                    if (x > maxX)
                        x = maxX;
                }

                int y;
                if (rows.Contains(position.Row)) //Is y visible
                {
                    y = CustomScrollPosition.Y;
                }
                else
                {
                    if (isFixedTop)
                        y = 0;
                    else
                        y = position.Row - FixedRows;

                    //Check if the scrollable positioin if not outside the valid area
                    int maxY = GetScrollRows(displayRectangle.Height);
                    if (y > maxY)
                        y = maxY;
                }

                newScrollPosition = new Point(x, y);

                return true;
            }
        }