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

  • Home
  • SEARCH
  • 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 6676723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:01:41+00:00 2026-05-26T04:01:41+00:00

I have a DataGridView with several columns and several rows of data. One of

  • 0

I have a DataGridView with several columns and several rows of data. One of the columns is a DataGridViewCheckBoxColumn and (based on the other data in the row) I would like the option to “hide” the checkbox in some rows. I know how to make it read only but I would prefer it to not show up at all or at least display differently (grayed out) than the other checkboxes. Is this possible?

  • 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-26T04:01:41+00:00Added an answer on May 26, 2026 at 4:01 am

    Some workaround: make it read-only and change back color to gray.
    For one specific cell:

    dataGridView1.Rows[2].Cells[1].Style.BackColor =  Color.LightGray;
    dataGridView1.Rows[2].Cells[1].ReadOnly = true;
    

    Or, better but more “complicated” solution:
    suppose you have 2 columns: first with number, second with checkbox, that should not be visible when number > 2. You can handle CellPainting event, paint only borders (and eg. background) and break painting of rest. Add event CellPainting for DataGridView (optionally test for DBNull value to avoid exception when adding new data in empty row):

    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
        //check only for cells of second column, except header
        if ((e.ColumnIndex == 1) && (e.RowIndex > -1))
        {
            //make sure not a null value
            if (dataGridView1.Rows[e.RowIndex].Cells[0].Value != DBNull.Value)
            {
                //put condition when not to paint checkbox
                if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value) > 2)
                {
                    e.Paint(e.ClipBounds, DataGridViewPaintParts.Border | DataGridViewPaintParts.Background);  //put what to draw
                    e.Handled = true;   //skip rest of painting event
                }
            }
        }
    }
    

    It should work, however if you change value manually in first column, where you check condition, you must refresh the second cell, so add another event like CellValueChanged:

    private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 0)
        {
            dataGridView1.InvalidateCell(1, e.RowIndex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView (datagridview2) with several columns of data. I have a local
I have a DataGridview with several columns, and one of the column is DataGridViewComboBoxColumn.
I have dataGridView with many columns and rows. Now I'd like to bind content
I have a datagridview made up of multiple rows and columns. I want to
I have a DataGridView where one of the columns is a DataGridViewComboBoxColumn . When
I have a DataGridView that is populated with 4 columns and multiple rows of
I have a DataTable which is bound to DataGridView . DataTable has several columns
I have a DataGridView and I need to add several (say 20) columns to
I have a DataGridView that has three read only columns in it and one
I have datagridview which fills data from database, there are columns where I have

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.