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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:24:37+00:00 2026-06-16T15:24:37+00:00

Without explaining the entire context, my problem is basically this: I have a datagridview

  • 0

Without explaining the entire context, my problem is basically this:

I have a datagridview on a Windows Form which is bound to an Entity Framework DbSet: dbSet<TEntity>.Local.ToBindingList().

If I set the datagridview’s ReadOnly property to true (in design view), and then have this statement in my code:

  myDataGridView.Rows[rowIndex].ReadOnly = false;

It steps right through without changing the value! (And no, my datasource is not readonly.)

Looping through the cells in the row and setting each cell’s ReadOnly property individually doesn’t work either:

  foreach (DataGridViewCell cell in myDataGridView.Rows[rowIndex].Cells)
  {
      cell.ReadOnly = false;
  }

.ReadOnly – Gets or sets a value indicating whether the user can edit the cells of the DataGridView control. But it’s acting like it can’t set for some reason.

Is there a reason that this would happen? I was thinking that maybe the datagridview’s ReadOnly property would override any changes made to specific rows/cells (ie. the whole form has to be either readonly or not), but apparently this worked for someone…

There are other ways to accomplish my end-goal, but I would like to know why I can’t change this property, as this would be the simplest solution for my situation.


EDIT:

Let me try to clarify my question:

Again, I am aware that there are other ways to accomplish my end-goal, but would like an answer to this issue:

Sorry for the primitive example, but to easily replicate the issue, create a WinForm application, throw a datagridview on it, and past this code into your project:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.ReadOnly = true;
        string[] row1 = new string[] { "test", "test1" };
        string[] row2 = new string[] { "test2", "test3" };
        string[] row3 = new string[] { "test4", "test5" };
        dataGridView1.Columns.Add("1", "1");
        dataGridView1.Columns.Add("2", "2");
        dataGridView1.Rows.Add(row1);
        dataGridView1.Rows.Add(row2);
        dataGridView1.Rows.Add(row3);

        dataGridView1.Rows[1].ReadOnly = false;
    }
}

If you put a breakpoint on the last line, and step through it, you will see that the ReadOnly property DOES NOT CHANGE! Why??

  • 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-16T15:24:38+00:00Added an answer on June 16, 2026 at 3:24 pm

    So I have found a solution/workaround for my question, althought I am still unsure of the reasons WHY…

    Apparently, if you want to change the ReadOnly property of a DataGridView row by row, you cannot set the main DataGridView.ReadOnly property, as evidently this overrides any subsequent changes.

    To reuse my previous example, the workaround would be to loop through the rows and set each ROW’s ReadOnly property (as opposed to setting the datagridview’s ReadOnly property), THEN you can change each row’s ReadOnly property individually:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            //dataGridView1.ReadOnly = true;
            string[] row1 = new string[] { "test", "test1" };
            string[] row2 = new string[] { "test2", "test3" };
            string[] row3 = new string[] { "test4", "test5" };
            dataGridView1.Columns.Add("1", "1");
            dataGridView1.Columns.Add("2", "2");
            dataGridView1.Rows.Add(row1);
            dataGridView1.Rows.Add(row2);
            dataGridView1.Rows.Add(row3);
    
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.ReadOnly = true;
            }
    
            dataGridView1.Rows[1].ReadOnly = false;
        }
    }
    

    This is working great for me, however any insight as to why the code in my original question does not work correctly would be appreciated!

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

Sidebar

Related Questions

I have been trying to ask this before, without any luck of explaining/proving a
I saw the help in Matlab, but they have provided an example without explaining
I will try explaining the problem in as much detail as I can, without
One recommends me the following code apparently only in .zshrc without explaining its purpose
Without going into whether this is a good or bad idea: Is it possible
without getting too verbose....i have been learning AS3 over the last week by building
I am trying to make a range control which is basically a slider control
There are a whole bunch of tutorials out there explaining how to do this,
Today, my boss told the below SQL query and went out without explaining it.
I have found many references explaining how to programmatically compile a Java class using

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.