One solution is using two controls in each column, one readonly, one not readonly and select them via DynamicCurrentControl. You also might try setting readonly in AfterRowColchange, which could be less work, but Dynamic properties are sure to work automatically in any way of row changes, also from outside via GOTO, SIP, LOCATE or SEEK, which all don't cause the grid event. Don't forget to set the columns sparse to .F. to let each row show it's differing control, even if it just differs in the readonly.
Another possibility would be to write code in the grid's (or column's?) When event. When the event fires, test to see if the current record meets your criteria for read-only. If it does, return .F., which prevents the grid from receiving focus; otherwise return .T.
Keep in mind that this will prevent the user from giving focus to the grid, regardless of whether or not they want to edit a control. So, for example, they will not be able to select and copy text.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
As Mike says himself the dynamic reaction of the When() event of column controls to return .T. or .F. does not translate to readonly, but to enabled. Another alternative with the same disadvantage is setting AllowCellSelection, it even is worse in preventing selection of all rows, also of allowed rows, so When() already is a better choice. You might set Readonly in When(), but that'll only reveal the readonly status in the moment the user clicks.
On further thought, I think Olaf's original idea is better: populate the column with two controls, and use DynamicCurrentControl to select between them. This has the advantage of not only making the relevant rows read-only, but also you have the opportunity to provide a visual indication that a given row is read-only. For example, you could make the read-only controls a bit dimmer, or give them a grey-ish BackColor.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
I was just today working on a form where I modify Enabled and ReadOnly for a control in the grid's AfterRowColChange. It affects the whole column, but since I re-evaluated every time I move to a new row, I get the right behavior.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.