Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3457450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:51:41+00:00 2026-05-18T09:51:41+00:00

I have the following cell which is used for my custom column data type

  • 0

I have the following cell which is used for my custom column data type on my data grid.

public class DataGridViewReviewerCell : DataGridViewCell
{
    protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle,
                                                TypeConverter valueTypeConverter,
                                                TypeConverter formattedValueTypeConverter,
                                                DataGridViewDataErrorContexts context)
    {
        return Value;
    }

    protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                  DataGridViewElementStates cellState, object value, object formattedValue,
                                  string errorText, DataGridViewCellStyle cellStyle,
                                  DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                  DataGridViewPaintParts paintParts)
    {
        base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, "", "", errorText,
                 cellStyle, advancedBorderStyle, paintParts);
        var parent = (DataGridViewReviewerColumn) OwningColumn;
        var columnValue = (ReviewerCheckBox) Value;

        CheckBoxRenderer.DrawCheckBox(
            graphics,
            new Point(cellBounds.X + 4, cellBounds.Y + 4),
            new Rectangle(cellBounds.X + 2, cellBounds.Y + 4, cellBounds.Width, cellBounds.Height - (4 * 2)),
            "     " + columnValue.ReviewerEmployeeName,
            parent.InheritedStyle.Font, 
            TextFormatFlags.Left,
            false,
            (columnValue.IsChecked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal));

    }
}

This class works as expected however every time Paint() gets called the text (currently " " + columnValue.ReviewerEmployeeName) keeps getting layered creating very unreadable text. I can’t seem to find anything that will fix this problem.

Slow piece of code

Here is the piece of code that is running very slowly. When I put this in debug mode it seems to be running endlessly.

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            dataGridView1.Rows.Add("STEP A", new ReviewerCheckBox());
            dataGridView1.Rows.Add("STEP B", new ReviewerCheckBox());
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.ColumnIndex != 1) return;

            var cell = (ReviewerCheckBox) dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            cell.IsChecked = !cell.IsChecked;
            cell.ReviewerEmployeeName = (cell.IsChecked ? Environment.UserName : String.Empty);

            //MessageBox.Show("Testing");
        }
    }

    public class ReviewerCheckBox
    {
        public string ReviewerEmployeeName { get; set; }
        public bool IsChecked { get; set; }
        public bool IsRequired { get; set; }
    }
}

    public class DataGridViewReviewerColumn : DataGridViewColumn
    {
        public DataGridViewReviewerColumn()
        {
            CellTemplate = new DataGridViewReviewerCell();
            ReadOnly = false;
            SortMode = DataGridViewColumnSortMode.NotSortable;
            Resizable = DataGridViewTriState.False;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:51:42+00:00Added an answer on May 18, 2026 at 9:51 am

    You should be checking the paintParts argument to determine which parts you should be drawing. For example if the background needs drawing, the DataGridViewPaintParts.Backgound flag will be set.

    if (paintParts.HasFlag(DataGridViewPaintParts.Background))
    {
      using (SolidBrush cellBackground =
        new SolidBrush(cellStyle.BackColor))
      {
        graphics.FillRectangle(cellBackground, cellBounds);
      }    
    }
    
    if (paintParts.HasFlag(DataGridViewPaintParts.Border))
    {
      PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
        advancedBorderStyle);
    }
    
    // Paint you cell content here
    

    Here is a slightly more complete example

    using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Windows.Forms.VisualStyles;
    
    namespace HideMainWinForm
    {
      class DataGridViewReviewerCell : DataGridViewCell
      {
        protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
        {
          return value;
        }
    
        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)
        {
          if (paintParts.HasFlag(DataGridViewPaintParts.Background))
          {
            using (SolidBrush cellBackground =
              new SolidBrush(cellStyle.BackColor))
            {
              graphics.FillRectangle(cellBackground, cellBounds);
            }
          }
    
          if (paintParts.HasFlag(DataGridViewPaintParts.Border))
          {
            PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
              advancedBorderStyle);
          }
    
          if (value != null)
          {
            CheckBoxRenderer.DrawCheckBox(
              graphics,
              new Point(cellBounds.X + 4, cellBounds.Y + 4),
              new Rectangle(cellBounds.X+24,cellBounds.Y+4, cellBounds.Width-24, cellBounds.Height-4),
              formattedValue.ToString(),
              OwningColumn.InheritedStyle.Font,
              TextFormatFlags.Left,
              false,
              CheckBoxState.CheckedNormal);
          }
        }
      }
    }
    

    The two HasFlag function calls can be translated to

    if ((paintParts & DataGridViewPaintParts.Background) == 
        DataGridViewPaintParts.Background)
    {
      ...
    }
    
    if ((paintParts & DataGridViewPaintParts.Border) == 
        DataGridViewPaintParts.Border)
    {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I have is following: <xsl:variable name=myvar select=.//spss:category[((not @varName) or @varName=$colVarName) and @text=$series]/spss:cell/@text/> What
To outline: I have a parser that grabs Cell references using the following regex
In excel 2007, I have a formula in a cell like the following: =COUNTIFS('2008-10-31'!$C:$C;>=&'$A7)
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have a Delphi application which reads data from an excel spreadsheet using code
i have following code to create cell and add image to it UIImageView* MyImage
I have got ot the following css to make my table cell's background transparent
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.