Paint a cell in DataGridView
-
If i want to paint one cell in dataGridView. How do i do it. dataGrid.Rows[count].Cells[1] Suppose if i want to paint the whole cell as white or red how do it do it. Where dataGrid above is DataGridView
-
If i want to paint one cell in dataGridView. How do i do it. dataGrid.Rows[count].Cells[1] Suppose if i want to paint the whole cell as white or red how do it do it. Where dataGrid above is DataGridView
You
kalyanPaladugu wrote:
if i want to paint the whole cell as white or red how do it do it
Derive a new type, a custom DataGridView cell. You can then control the painting yourself. Also, you might want to look at the cell's Paint event.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
You
kalyanPaladugu wrote:
if i want to paint the whole cell as white or red how do it do it
Derive a new type, a custom DataGridView cell. You can then control the painting yourself. Also, you might want to look at the cell's Paint event.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
I used the below method to paint all the cells of the column in the datagridview but when i maximize and minimize the windows form the effect of painting becomes bad. Any thoughts how to rectify that. Basically by the code below iam erasing the cells in the particular column called col void dataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e) { if (this.dataGridView1.Columns["Col"].Index == e.ColumnIndex && e.RowIndex >= 0) { using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { Rectangle newRect = new Rectangle(e.CellBounds.X +3,e.CellBounds.Y + 3, e.CellBounds.Width - 3, e.CellBounds.Height - 3); e.Graphics.FillRectangle(backColorBrush, newRect); e.Handled = true; } } }
-
I used the below method to paint all the cells of the column in the datagridview but when i maximize and minimize the windows form the effect of painting becomes bad. Any thoughts how to rectify that. Basically by the code below iam erasing the cells in the particular column called col void dataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e) { if (this.dataGridView1.Columns["Col"].Index == e.ColumnIndex && e.RowIndex >= 0) { using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { Rectangle newRect = new Rectangle(e.CellBounds.X +3,e.CellBounds.Y + 3, e.CellBounds.Width - 3, e.CellBounds.Height - 3); e.Graphics.FillRectangle(backColorBrush, newRect); e.Handled = true; } } }
I don't know what the problem is, but I will say that just the other day another poster in this forum encountered problems while handling the dataGridView.CellPainting event. He got around his problem by just creating a custom cell type and overriding the painting himself.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
I don't know what the problem is, but I will say that just the other day another poster in this forum encountered problems while handling the dataGridView.CellPainting event. He got around his problem by just creating a custom cell type and overriding the painting himself.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
I wanted to do the same thing and found some code similar to what kalyanPaladugu posted in the msdn. At least for me it seemed to work well. I guess creating a custom cell type also has its charme. I will use that idea when I want to do a little more than just do some painting. Thanks for the tip, Erik