Reputation: 165
Can anyone explain this?
This works
TrandetlDataGridView.ReadOnly = False
TrandetlDataGridView.CurrentRow.ReadOnly = True
This does not
TrandetlDataGridView.ReadOnly = True
TrandetlDataGridView.CurrentRow.ReadOnly = False
Upvotes: 0
Views: 114
Reputation: 9479
The DataGridView.ReadOnly
property will OVERRIDE any row/col/cell read only property “IF” the grids read only property is set to true
. This can be seen in the second posted code that “doesn’t” work.
As per MS documentation for the DataGridViewRow.ReadOnly
property in the remarks section…
Setting this property has no effect if the value of the DataGridView.ReadOnly property is true.
A possible solution is to leave the “grids” read only property as false
, then loop through the grid rows and set each row’s read only property to true
. Then, it should work as expected.
The example below is in C#, however the same idea would apply using VB.
First a method to loop through the grid and set each row’s read only property to true
…
private void SetRowsReadOnly() {
foreach (DataGridViewRow row in TrandetlDataGridView.Rows) {
row.ReadOnly = true;
}
}
Then, using your “doesn’t work” example, replace setting the grids read only property with a call to the method above and it should work as expected.
private void button2_Click(object sender, EventArgs e) {
SetRowsReadOnly();
TrandetlDataGridView.CurrentRow.ReadOnly = false;
}
Hope this helps.
Upvotes: 1