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 7698461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:14:53+00:00 2026-05-31T22:14:53+00:00

Hi Programmers, I need to add the checkbox and label in the same cell.I

  • 0

Hi Programmers,
I need to add the checkbox and label in the same cell.I do know how to do that. I can make the datagridviewcolumn to checkbox but then it only shows the checkbox and no place to show label. Can anybody wake me up from this nightmare?
Thanks in advance.

  • 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-31T22:14:54+00:00Added an answer on May 31, 2026 at 10:14 pm

    I don’t believe this is possible with the out of the box CheckBoxCell.

    Here is an implementation which subclasses the check box column and does some custom painting to draw the label. It is possible to extend this in various ways, such as offering binding for the label text (it currently requires the label text being set directly). My code borrows heavily from this forum post.

    using System;
    using System.Windows.Forms;
    using System.Drawing;
    
    public class MyDGVCheckBoxColumn : DataGridViewCheckBoxColumn
    {
        private string label;
    
        public string Label
        {
            get
            {
                return label;
            }
            set
            {
                label = value;
            }
        }
    
        public override DataGridViewCell CellTemplate
        {
            get
            {
                return new MyDGVCheckBoxCell();
            }
        }
    }
    
    public class MyDGVCheckBoxCell : DataGridViewCheckBoxCell
    {
        private string label;
    
        public string Label
        {
            get
            {
                return label;
            }
            set
            {
                label = value;
            }
    
        }
    
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
    
            // the base Paint implementation paints the check box
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
    
            // Get the check box bounds: they are the content bounds
            Rectangle contentBounds = this.GetContentBounds(rowIndex);
    
            // Compute the location where we want to paint the string.
            Point stringLocation = new Point();
    
            // Compute the Y.
            // NOTE: the current logic does not take into account padding.
            stringLocation.Y = cellBounds.Y + 2;
    
    
            // Compute the X.
            // Content bounds are computed relative to the cell bounds
            // - not relative to the DataGridView control.
            stringLocation.X = cellBounds.X + contentBounds.Right + 2;
    
    
            // Paint the string.
            if (this.Label == null)
            {
                MyDGVCheckBoxColumn col = (MyDGVCheckBoxColumn)this.OwningColumn;
                this.label = col.Label;
            }
    
            graphics.DrawString(
            this.Label, Control.DefaultFont, System.Drawing.Brushes.Red, stringLocation);
    
        }
    
    }
    

    Here is code showing the usage:

    private void Form1_Load(object sender, EventArgs e)
    {
        MyDGVCheckBoxColumn col = new MyDGVCheckBoxColumn();
        col.Label = "hippo";
        col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
        this.dataGridView1.Columns.Add(col);
        this.dataGridView1.RowCount = 5;
    
        foreach (DataGridViewRow row in this.dataGridView1.Rows)
        {
            if (row.Index % 2 == 0)
            {
                ((MyDGVCheckBoxCell)row.Cells[0]).Label = "kitten";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sadly, I have a legacy PHP4 system that I continuously need to add features
I have a challenge I need some input on. I am currently recruiting programmers
The people writing the user manual are not necessarily programmers, and they need a
I am C++ programmer and I need to make some changes to VB6 code.
I think most C++ programmers here would agree that polluting the global namespace is
I always hear that programmers try to pick the right tool for the job.
I have a UIImageView that I want to add a shadow behind. I wish
I have a software that allow to write add-on in javascript files (.js) that
I think I know what #ifdefs I need to use to be x86-32 and
I need to add some UCs for my app and I want to enable

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.