Without explaining the whole context, my problem is basically this:
I have a datagridview on a Windows Form that is associated with the Entity Framework DbSet: dbSet<TEntity>.Local.ToBindingList() .
If I set the datagridview ReadOnly property to true (in design mode), then this statement in my code:
myDataGridView.Rows[rowIndex].ReadOnly = false;
It works without changing the value! (And no, my data source is not just readable.)
Passing through the cells in a row and setting each ReadOnly property of each cell also does not work:
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. For some reason he cannot install .
Is there a reason this will happen? I thought it might be that the datagridview ReadOnly property will override any changes made to specific rows / cells (i.e. the whole form should be either readonly or not), but apparently this worked for someone ...
There are other ways to achieve the ultimate goal, but I would like to know why I cannot change this property, as this would be the easiest solution for my situation.
<h / "> EDIT:
Let me clarify my question:
Again, I know that there are other ways to achieve my ultimate goal, but I would like to answer this question:
Sorry for the primitive example, but to easily replicate the problem, create a WinForm application, drop a datagridview on it and skip 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 set a breakpoint on the last line and go through it, you will see that the ReadOnly property DOES NOT CHANGE! Why??