
07-02-2012, 02:55 PM
|
|
Centurion
|
|
Join Date: Apr 2006
Posts: 100
|
|
From my experience with DGVs, altering cells like that doesn't work as intended. It's probably better to clone the whole row, alter the cell the way you want it to be, then reinsert the row at the same index that you removed it.
Code:
If e.Button Is ToolBarButton1 Then
For Each dvgr As DataGridViewRow In DgvPracExcl.Rows
If dvgr.Cells(2).ToString() = "old" Then
dvgr.Cells(3).ReadOnly = True
Else
dvgr.Cells(3).ReadOnly = False
End If
DgvPracExcl.Rows.Insert(dvgr.Index, dvgr)
'.Insert inserts the row where the index points to and shifts the other rows down.
'Don't forget to remove the row that got shifted down because it's identical to the one you just inserted minus the readonly cell
DgvPracExcl.Rows.RemoveAt(dvgr.Index + 1)
Next
End If
I can't guarantee that that'll work, but I think it has a better chance than altering the cells while they're in the DGV. You might even have to change the row template of the row you clone.
|
|