protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            // Is the mouse hovering over this cell?
            if ((inCell == rowIndex) &&
                ((cellState & DataGridViewElementStates.Selected) !=
                 DataGridViewElementStates.Selected))
            {
                // Get the rectangle where painting will take place.
                Rectangle rect = new Rectangle(cellBounds.X, cellBounds.Y,
                                               cellBounds.Width - 1, cellBounds.Height - 1);

                // Render the custom cell background.
                Color gradientColor;
                GradientRolloverColumn gradientColumn = this.OwningColumn as GradientRolloverColumn;
                if (gradientColumn != null)
                {
                    gradientColor = ((GradientRolloverColumn)base.OwningColumn).GradientColor;
                }
                else
                {
                    gradientColor = Color.Blue;
                }


                using (LinearGradientBrush brush = new LinearGradientBrush(rect,
                                                                           Color.White, gradientColor, 35f))
                {
                    graphics.FillRectangle(brush, rect);
                }

                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                           value, formattedValue, errorText, cellStyle, advancedBorderStyle,
                           paintParts & ~(DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground));
            }
            else
            {
                // Perform the standard painting.
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                           value, formattedValue, errorText, cellStyle, advancedBorderStyle,
                           paintParts);
            }
        }
Example #2
0
		private void CustomCell_Load(object sender, EventArgs e)
		{
			
			dataGridView1.DataSource = Program.StoreDB.GetProducts();

			// Hide the ordinary version of this column.
			dataGridView1.Columns[0].Visible = false;

			// Create custom column.
			GradientRolloverColumn colGradient = new GradientRolloverColumn(Color.SlateBlue);
			colGradient.DataPropertyName = dataGridView1.Columns[0].DataPropertyName;
			colGradient.HeaderText = dataGridView1.Columns[0].HeaderText;
			colGradient.Width = dataGridView1.Columns[0].Width;
			colGradient.ReadOnly = dataGridView1.Columns[0].ReadOnly;
			colGradient.ValueType = dataGridView1.Columns[0].ValueType;
			colGradient.DisplayIndex = 0;

			// Add the custom column.
			dataGridView1.Columns.Add(colGradient);
		}
        private void CustomCell_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Program.StoreDB.GetProducts();

            // Hide the ordinary version of this column.
            dataGridView1.Columns[0].Visible = false;

            // Create custom column.
            GradientRolloverColumn colGradient = new GradientRolloverColumn(Color.SlateBlue);

            colGradient.DataPropertyName = dataGridView1.Columns[0].DataPropertyName;
            colGradient.HeaderText       = dataGridView1.Columns[0].HeaderText;
            colGradient.Width            = dataGridView1.Columns[0].Width;
            colGradient.ReadOnly         = dataGridView1.Columns[0].ReadOnly;
            colGradient.ValueType        = dataGridView1.Columns[0].ValueType;
            colGradient.DisplayIndex     = 0;

            // Add the custom column.
            dataGridView1.Columns.Add(colGradient);
        }