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

OnPaintCell() protected method

Paints the Cell at the specified row and column indexes
protected OnPaintCell ( PaintEventArgs e, int row, int column, Rectangle cellRect ) : void
e PaintEventArgs A PaintEventArgs that contains the event data
row int The index of the row that contains the cell to be painted
column int The index of the column that contains the cell to be painted
cellRect Rectangle The bounding Rectangle of the Cell
return void
        protected void OnPaintCell(PaintEventArgs e, int row, int column, Rectangle cellRect)
        {
            if (this.TableModel == null || this.ColumnModel == null)
            {
                return;
            }

            var currentCell = this.TableModel[row, column];
            var currentRow = this.TableModel.Rows[row];
            var currentColumn = this.ColumnModel.Columns[column];

            if (currentColumn == null)
            {
                return;
            }

            // get the renderer for the cells column
            ICellRenderer renderer = currentColumn.Renderer;
            if (renderer == null)
            {
                // get the default renderer for the column
                renderer = this.ColumnModel.GetCellRenderer(currentColumn.GetDefaultRendererName());
            }

            // if the renderer is still null (which it shouldn't)
            // the get out of here
            if (renderer == null)
            {
                return;
            }

            ////////////
            // Adjust the rectangle for this cell to include any cells that it colspans over
            Rectangle realRect = cellRect;
            var pcea = new PaintCellEventArgs(e.Graphics, realRect);

            bool isEnabled = false;
            bool isEditable = false;
            if (currentCell != null)
            {
                isEditable = currentCell.Editable && currentRow.Editable && currentColumn.Editable;
                isEnabled = currentCell.Enabled && currentRow.Enabled && currentColumn.Enabled;

                if (currentCell.ColSpan > 1)
                {
                    int width = this.GetColumnWidth(column, currentCell);
                    realRect = new Rectangle(cellRect.X, cellRect.Y, width, cellRect.Height);
                }

                if (currentCell.ImageSizeMode == ImageSizeMode.NoClip)
                {
                    pcea.Graphics.SetClip(e.ClipRectangle);
                }
                else
                {
                    pcea.Graphics.SetClip(Rectangle.Intersect(e.ClipRectangle, realRect));
                }
            }

            if (column < currentRow.Cells.Count)
            {
                // is the cell selected
                bool isSelected = false;

                if (this.FullRowSelect)
                {
                    isSelected = this.TableModel.Selections.IsRowSelected(row);
                }
                else
                {
                    if (this.SelectionStyle == SelectionStyle.ListView)
                    {
                        if (this.TableModel.Selections.IsRowSelected(row) && this.ColumnModel.PreviousVisibleColumn(column) == -1)
                        {
                            isSelected = true;
                        }
                    }
                    else if (this.SelectionStyle == SelectionStyle.Grid)
                    {
                        if (this.TableModel.Selections.IsCellSelected(row, column))
                        {
                            isSelected = true;
                        }
                    }
                }

                // draw the cell
                pcea.SetCell(currentCell);
                pcea.SetRow(row);
                pcea.SetColumn(column);
                pcea.SetTable(this);
                pcea.SetSelected(isSelected);
                pcea.SetFocused(this.Focused && this.FocusedCell.Row == row && this.FocusedCell.Column == column);
                pcea.SetSorted(column == this.lastSortedColumn);
                pcea.SetEditable(isEditable);
                pcea.SetEnabled(isEnabled);
                pcea.SetCellRect(realRect);
            }
            else
            {
                // there isn't a cell for this column, so send a
                // null value for the cell and the renderer will
                // take care of the rest (it should draw an empty cell)
                pcea.SetCell(null);
                pcea.SetRow(row);
                pcea.SetColumn(column);
                pcea.SetTable(this);
                pcea.SetSelected(false);
                pcea.SetFocused(false);
                pcea.SetSorted(false);
                pcea.SetEditable(false);
                pcea.SetEnabled(false);
                pcea.SetCellRect(realRect);
            }

            // let the user get the first crack at painting the cell
            this.OnBeforePaintCell(pcea);

            // only send to the renderer if the user hasn't
            // set the handled property
            if (!pcea.Handled)
            {
                renderer.OnPaintCell(pcea);
            }

            // let the user have another go
            this.OnAfterPaintCell(pcea);
        }
Table