XPTable.Models.Table.EnsureVisible C# (CSharp) Method

EnsureVisible() public method

Ensures that the Cell at the specified row and column is visible within the Table, scrolling the contents of the Table if necessary
public EnsureVisible ( int row, int column ) : bool
row int The zero-based index of the row to scroll into view
column int The zero-based index of the column to scroll into view
return bool
        public bool EnsureVisible(int row, int column)
        {
            if (!this.Scrollable || (!this.HScroll && !this.VScroll) || row == -1)
            {
                return false;
            }

            if (column == -1)
            {
                if (this.FocusedCell.Column != -1)
                {
                    column = this.FocusedCell.Column;
                }
                else
                {
                    column = 0;
                }
            }

            int hscrollVal = this.hScrollBar.Value;
            int vscrollVal = this.vScrollBar.Value;
            if (this.HScroll)
            {
                if (column < 0)
                {
                    column = 0;
                }
                else if (column >= this.ColumnCount)
                {
                    column = this.ColumnCount - 1;
                }

                if (this.ColumnModel.Columns[column].Visible)
                {
                    if (this.ColumnModel.Columns[column].Left < this.hScrollBar.Value)
                    {
                        hscrollVal = this.ColumnModel.Columns[column].Left;
                    }
                    else if (this.ColumnModel.Columns[column].Right > this.hScrollBar.Value + this.CellDataRect.Width)
                    {
                        if (this.ColumnModel.Columns[column].Width > this.CellDataRect.Width)
                        {
                            hscrollVal = this.ColumnModel.Columns[column].Left;
                        }
                        else
                        {
                            hscrollVal = this.ColumnModel.Columns[column].Right - this.CellDataRect.Width;
                        }
                    }

                    if (hscrollVal > this.hScrollBar.Maximum - this.hScrollBar.LargeChange)
                    {
                        hscrollVal = this.hScrollBar.Maximum - this.hScrollBar.LargeChange;
                    }
                }
            }

            if (this.VScroll)
            {
                if (row < 0)
                {
                    vscrollVal = 0;
                }
                else if (row >= this.RowCount)
                {
                    vscrollVal = this.RowCount - 1;
                }
                else
                {
                    int hidden = tableModel.Rows.HiddenRowCountBefore(row);

                    if (row < vscrollVal)
                    {
                        vscrollVal = row;
                    }
                    else if (row - hidden > vscrollVal + this.vScrollBar.LargeChange)
                    {
                        vscrollVal += row - (vscrollVal + this.vScrollBar.LargeChange);
                    }
                }

                if (vscrollVal > this.vScrollBar.Maximum - this.vScrollBar.LargeChange)
                {
                    vscrollVal = (this.vScrollBar.Maximum - this.vScrollBar.LargeChange) + 1;
                }
            }

            if (this.RowRect(row).Bottom > this.CellDataRect.Bottom)
            {
                vscrollVal++;
            }

            var moved =
                  SetScrollValue(this.hScrollBar, hscrollVal)
                | SetScrollValue(this.vScrollBar, vscrollVal);

            if (moved)
            {
                this.Invalidate(this.PseudoClientRect);
            }

            return moved;
        }

Same methods

Table::EnsureVisible ( XPTable.Models.CellPos cellPos ) : bool

Usage Example

Ejemplo n.º 1
0
        void previius()
        {
            CellPos cell = new CellPos((int)numericUpDown1.Value, 0);

            table.TableModel.Selections.AddCell(cell);
            table.EnsureVisible(cell);
        }
Table