06-01-2023
01:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-01-2023
01:52 PM
Hi Maxim - the CellPainting event is not a good place to do this. That's more suited for customizing the appearance of the cell.
Here's a new version of your rule. This sets the read-only state with the same logic that you were using in oDgv_CellPainting. But it does it in the Form.Shown event. The system will call that only once, and it will call it after the DataGridView has been populated. So that's a good time to set some cells to read-only.
I also made a small change to the Rows.Add() lines. You were calling them with the columns count as an argument. I think that value is ignored, so I took it out just to make the code more clear. Let me know if I missed something here.

Mike Deck
Software Developer
Autodesk, Inc.