The c # (vs) dategridview control inheritance cannot be modified,

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.