Exemple #1
0
        /// <summary>
        /// Paints the Cell at the specified row and column indexes
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data</param>
        /// <param name="row">The index of the row that contains the cell to be painted</param>
        /// <param name="column">The index of the column that contains the cell to be painted</param>
        /// <param name="cellRect">The bounding Rectangle of the Cell</param>
        protected void OnPaintCell(PaintEventArgs e, int row, int column, Rectangle cellRect)
        {
            if (row == 0 && column == 1)
            {
                column = 1;
            }

            // get the renderer for the cells column
            ICellRenderer renderer = this.ColumnModel.Columns[column].Renderer;
            if (renderer == null)
            {
                // get the default renderer for the column
                renderer = this.ColumnModel.GetCellRenderer(this.ColumnModel.Columns[column].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;
            Cell thisCell = this.TableModel[row, column];
            if (thisCell != null && thisCell.ColSpan > 1)
            {
                int width = this.GetColumnWidth(column, thisCell);
                realRect = new Rectangle(cellRect.X, cellRect.Y, width, cellRect.Height);
            }
            ////////////

            // For the last column, extend the width of the cell to fill the grid, including the vertical scrollbar (to avoid a blank space where the scrollbar would be).
            if (column == this.ColumnModel.Columns.Count - 1)
            {
                //realRect.Width += SystemInformation.VerticalScrollBarWidth;
            }

            PaintCellEventArgs pcea = new PaintCellEventArgs(e.Graphics, realRect);

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

            if (column < this.TableModel.Rows[row].Cells.Count)
            {
                // is the cell selected
                bool selected = false;

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

                //
                bool editable = this.TableModel[row, column].Editable && this.TableModel.Rows[row].Editable && this.ColumnModel.Columns[column].Editable;
                bool enabled = this.TableModel[row, column].Enabled && this.TableModel.Rows[row].Enabled && this.ColumnModel.Columns[column].Enabled;

                // draw the cell
                pcea.SetCell(this.TableModel[row, column]);
                pcea.SetRow(row);
                pcea.SetColumn(column);
                pcea.SetTable(this);
                pcea.SetSelected(selected);
                pcea.SetFocused(this.Focused && this.FocusedCell.Row == row && this.FocusedCell.Column == column);
                pcea.SetSorted(column == this.lastSortedColumn);
                pcea.SetEditable(editable);
                pcea.SetEnabled(enabled);
                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);
        }
Exemple #2
0
		/// <summary>
		/// Paints the Cell at the specified row and column indexes
		/// </summary>
		/// <param name="e">A PaintEventArgs that contains the event data</param>
		/// <param name="row">The index of the row that contains the cell to be painted</param>
		/// <param name="column">The index of the column that contains the cell to be painted</param>
		/// <param name="cellRect">The bounding Rectangle of the Cell</param>
		protected void OnPaintCell(PaintEventArgs e, int row, int column, Rectangle cellRect)
		{
			if (row == 0 && column == 1)
			{
				column = 1;
			}
			
			// get the renderer for the cells column
			ICellRenderer renderer = this.ColumnModel.Columns[column].Renderer;
			if (renderer == null)
			{
				// get the default renderer for the column
				renderer = this.ColumnModel.GetCellRenderer(this.ColumnModel.Columns[column].GetDefaultRendererName());
			}

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

			PaintCellEventArgs pcea = new PaintCellEventArgs(e.Graphics, cellRect);
			pcea.Graphics.SetClip(Rectangle.Intersect(e.ClipRectangle, cellRect));

			if (column < this.TableModel.Rows[row].Cells.Count)
			{
				// is the cell selected
				bool selected = false;

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

				//
				bool editable = this.TableModel[row, column].Editable && this.TableModel.Rows[row].Editable && this.ColumnModel.Columns[column].Editable;
				bool enabled = this.TableModel[row, column].Enabled && this.TableModel.Rows[row].Enabled && this.ColumnModel.Columns[column].Enabled;

				// draw the cell
				pcea.SetCell(this.TableModel[row, column]);
				pcea.SetRow(row);
				pcea.SetColumn(column);
				pcea.SetTable(this);
				pcea.SetSelected(selected);
				pcea.SetFocused(this.Focused && this.FocusedCell.Row == row && this.FocusedCell.Column == column);
				pcea.SetSorted(column == this.lastSortedColumn);
				pcea.SetEditable(editable);
				pcea.SetEnabled(enabled);
				pcea.SetCellRect(cellRect);
			}
			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(cellRect);
			}

			// 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);
		}
Exemple #3
0
        /// <summary>
        /// Paints the Cell at the specified row and column indexes
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data</param>
        /// <param name="row">The index of the row that contains the cell to be painted</param>
        /// <param name="column">The index of the column that contains the cell to be painted</param>
        /// <param name="cellRect">The bounding Rectangle of the Cell</param>
        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);
        }