The c # (vs) dategridview control inheritance cannot be modified,
Problem description: When I wrote a small project a few days ago, I used a parent form, and the inherited dategridview control cannot be modified whether it is a property or an event.
As shown in:
Then I went to the Internet to find information, but there were very few resources related to this issue, maybe I wouldn't find it. In short, I got three things based on the information:
① Most of the forums or posts on this issue were posted 10 years ago, and no effective solution was found.
② In this respect, simple controls can be modified after they are inherited. As long as they are changed to public, the complicated controls, such as the dategridview mentioned in this article, cannot be changed to anything, they said this was intentionally set by Microsoft, and some said it was a bug by Microsoft.
③ Some may say that although the control panel is gray, it cannot be modified, but it can be modified with code in the background. This is not completely correct. It is not just code, but also something has to be used.
In short, based on the continuous discussion and discussion, we finally come up with the following solutions:
For example, if I want to register a double-click cell event for the control, first click the event in the dategridview of the parent form (change the permission to public) and then go to the background code:
For example, you can change the original private to public and add a virtual file. That's right, you can use the virtual method to rewrite the file to implement the event in the subclass.
In the subform, the Panel is still gray and cannot be clicked. We can directly write it in the background code of the form.
Copy the empty Event code of the parent form directly, change virtual to override, and write in the Code body.
It has been verified that this method is feasible.