Entity and entity set-continued

Source: Internet
Author: User
The previous day, I posted a piece of entity and entity set Code .

1. entity class

Public   Class Orderinfo: ieditableobject, idataerrorinfo

The object class inherits the ieditableobject and idataerrorinfo interfaces.

ieditableobject is used in data binding. It mainly includes three functions: beginedit (), canceledit (), and endedit ().
when the collection object of the object class is bound to a DataGrid, if you click the last row in the DataGrid (winform) with the mouse, a new object is created, in addition, the DataGrid automatically calls the beginedit method in the ieditableobject interface of the object class. If you do not need to add one, press the ESC key on the disk to cancel typing. This DataGrid will automatically call the canceledit method in the ieditableobeject interface to cancel typing. In my code, a removeme event is triggered to the Collection object of the object class. At this time, orderinfocollection will remove the newly added orderinfo.
Of course, you can also use the three ieditable methods to perform rollback. For example, you can manually call beginedit to modify the data, and then use endedit to submit the modified data. If the modification is incorrect, you can use canceledit to roll back and forth.

for the idataerrorinfo interface, it has only two attributes: Public string error and Public string This [ string strerrorname], is actually used for data binding, if the added or modified data is incorrect (you can write a specific judgment in the error get method and return an error message), that is, when the error attribute is not equal, the DataGrid (which is also a winform) will provide the specific error information (which is actually the value of the error attribute) at the beginning of the row, without additional encoding. Of course, other data bindings can also achieve this effect.

There is anotherInternal ClassOrderinfoeventargs: eventargs is an empty class, but it is not needed for future expansion.

2. Collection of object classes

Public   Class Orderinfocollection: collectionbase, ibindinglist

For an object set, it inherits from the collectionbase class and the ibindinglist interface.

Inherit from collectionbase to complete functions similar to arraylist, such as ADD, clear, remove, and the new getenumerator () iteration method, so that you can use the orderinfocollection class in foreach.

The entity set implements the ibindinglist interface to bind data, including sorting and searching. For example, if orderinfocollection is bound to a DataGrid (winform), when you click the bottom empty line, if the allownew attribute of orderinfocollection returns true, it will automatically callObjectThe ibindinglist. addnew () method is used to create a new orderinfo, And the beginedit method of orderinfo is automatically called (if the ieditableobject interface is implemented in orderinfo ).

In addition, a listchanged event is added. This event is triggered when an operation is performed on the Set (after the modification and deletion are completed ).

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.