Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Paint a cell in DataGridView

Paint a cell in DataGridView

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalyanPaladugu
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • K kalyanPaladugu

      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

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • J Judah Gabriel 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

        K Offline
        K Offline
        kalyanPaladugu
        wrote on last edited by
        #3

        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; } } }

        J 1 Reply Last reply
        0
        • K kalyanPaladugu

          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; } } }

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          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

          E 1 Reply Last reply
          0
          • J Judah Gabriel 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

            E Offline
            E Offline
            Erik Molenaar
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups