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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:27:38+00:00 2026-06-14T17:27:38+00:00

I am new to posting on Stack. I have searched for quite some time

  • 0

I am new to posting on Stack. I have searched for quite some time to a problem similar to mine. I am trying to change the checkboxes in a WinForms DataGridView from not read-only to read-only based on the object’s boolean value dynamically.

It is showing in debug mode that the change has happened but once it fully runs through, the checkbox cells that are supposed to be read only are still allowing check and uncheck functionality. I have left the commented out section in to show that I have attempted to do this.

m_SingletonForm.dataGridView1.DataSource = list;
m_SingletonForm.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
m_SingletonForm.dataGridView1.Columns["StoreGroup"].ReadOnly = true;
m_SingletonForm.dataGridView1.Columns["Message"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
m_SingletonForm.dataGridView1[0, 0].ReadOnly = true;


foreach (DataGridViewRow row in m_SingletonForm.dataGridView1.Rows)
{
    //var isChecked = Convert.ToBoolean(row.Cells["SendFile"].Value);

    //if (!isChecked)
    //{
        //m_SingletonForm.dataGridView1.Rows[0].Cells["SendFile"].Style.BackColor = Color.Red;
        //m_SingletonForm.dataGridView1.Rows[0].Cells["SendFile"].ReadOnly = true;

        //m_SingletonForm.dataGridView1.Rows[row.Index].Cells["SendFile"].Style.BackColor = Color.Red;
        //m_SingletonForm.dataGridView1.Rows[row.Index].Cells["SendFile"].ReadOnly = true;
        //m_SingletonForm.dataGridView1["SendFile", row.Index].ReadOnly = true;
        //m_SingletonForm.dataGridView1["SendFile", row.Index].Style.BackColor = Color.Red;          
    // }
}

m_SingletonForm.label1.Text = message;
m_SingletonForm.Text = title;
MessageBox.Show(m_SingletonForm.dataGridView1[0, 0].ReadOnly.ToString());
m_SingletonForm.ShowDialog();

Any help would be greatly appreciated.

  • 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-06-14T17:27:39+00:00Added an answer on June 14, 2026 at 5:27 pm

    From the line m_SingletonForm.ShowDialog(); it appears that you have this code before the DataGridView has been displayed *. This is too early for such changes to the grid items to be applied. You would also see the same issue if your code was inside the constructor for your form.

    The simplest fix for the issue is to put you code for setting the cells to readonly within a DataBindingComplete event handler. Something like this:

    // Attach the event
    m_SingletonForm.dataGridView1.DataBindingComplete += new
        DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
    
    
    // And the code for the handler
    void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        foreach (DataGridViewRow row in m_SingletonForm.dataGridView1.Rows)
        {
            var isChecked = Convert.ToBoolean(row.Cells["SendFile"].Value);
    
            if (!isChecked)
            {
                m_SingletonForm.dataGridView1.Rows[0].Cells["SendFile"].Style.BackColor = Color.Red;
                m_SingletonForm.dataGridView1.Rows[0].Cells["SendFile"].ReadOnly = true;
    
                m_SingletonForm.dataGridView1.Rows[row.Index].Cells["SendFile"].Style.BackColor = Color.Red;
                m_SingletonForm.dataGridView1.Rows[row.Index].Cells["SendFile"].ReadOnly = true;
                m_SingletonForm.dataGridView1["SendFile", row.Index].ReadOnly = true;
                m_SingletonForm.dataGridView1["SendFile", row.Index].Style.BackColor = Color.Red;
            }
        }            
    }
    

    * I have never 100% worked out why it is this way – I believe it is related to the fact that there are two sets of cells in the DataGridView – the editing/ui cells and the data they sit upon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently integrating some new classes into an existing application. I have a JDialog
I have a similar issue to these posts : I'm posting separately to provide
I have a problem posting data in my database with a form. Very basic
I have searched a lot regarding my problem but no solution so i am
Well, I have been scratching my head for some time now. But failed to
I'm posting a file in Javascript using the new FormData interface. When I send
New to PHP and MySQL, have heard amazing things about this website from Leo
new to c#. I'm trying to make a simple system where I can search
new here and new to jQuery. I've searched for an answer to my question/
New to Node.js and Express, I am trying to understand the two seems overlapping

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.