Chinese information:
Introduction of data bindings and controls
When Microsoft has developed form controls and web controls, it is desperate to implement data binding. At that time, I was still VB, and they conducted a large number of functional program editing.
The most effective data binding is not what we said, but the object, structure, and object set. Data binding has a significant feature: implementing data binding controls in the web page, we don't do other operations. After data binding, only read operations, no other operations, that is, controls the information of the data source, just use, cannot operate. And when we are building other objects or ui, we don't need to care about it, and its operation is an eye.
Windows Form Control Data Binding can read and write, and some operation is more complicated. In this way, these data is called from the database and displayed in our UI control, once the data changes in the UI control, the data in the database also changes with it, of course, these operations do not need us to complete, but data Changing it will write more code. Due to the above features, we can use these features to our business and class, including:
1. Have a modification of data such as a UI.
2. The DataGrid data can be made correctly.
3. In DataGrid neutron objects can be edited.
4. Increase or delete sub-objects in DataGrid.
For a simple object, when we modify the correct data, I can complete the binding of the form data through an event.
Through these events, we can make UI's data to update at any time with our modification.
Once its correct rule is destroyed in the UI, we must know how to modify it. It also uses an unfinished event to bind data, which will make the binding error.
In addition, we have many options available here. For example, DataGrid is a commonly used binding control. With the correct use of our set, we can make DataGrid controls more self-energy.
We can use IbindingList and DataGrid together, which will be more convenient.
Finally, there is a significant feature in the integration, we are called a child object. Sub-objects can use IeditableObject to make DataGrid more convenient to data editing. When there is invalid data, the child object can use iDataRrinfo, so that the DataGrid is marked with the lower-drawer place. In short, we only need to write a little bit of code to make the DataGrid's advantages to the fullest.
Example of an example of a window binding:
Attribute binding of a control on a form is not a complex, give an example, see the simple ORDER class below:
Public Class Order
Private mid as string = "" "
Private MCUSTOMER AS STRING = ""
Public property ID () AS STRING
Get
Return MID
END GET
Set (byval value as string)
MID = Value
End set
End Property
Public property customer () AS STRING
Get
Return MCUSTOMER
END GET
Set (byval value as string)
MCUSTOMER = VALUE
End set
End Property
END CLASS
The relatively special code here is:
Private mid as string = "" "
Private MCUSTOMER AS STRING = ""
Note that the initialization of the variable here is no value, and when they declare when they declare when they declare, they are not very special.
Since we don't do this, data binding will fail. This indicates that the automatic initialization of the variable does not occur when data is bound to the object, and there is no initialized variable will thrown an exception when binding data.
So the declaration of the variable must be before the data binding, this means that we will initialize the variable before the data binding will let me avoid exceptions.
We built a form that binds the data to the properties of its controls when it is loaded.
The binding code is as follows:
Private Morder as Order
Private sub orderrentry_load (Byval Sender as system.object, _
BYVAL E as system.eventargs) Handles mybase.load
Morder = new Order ()
TXTID.DATABINDINGS.ADD ("Text", Morder, "ID")
TXTCUSTOMER.DATABINDINGS.ADD ("Text", Morder, "Customer")
End Sub
In fact, the controls on each form have a data binding connection. This connection library contains a series of data binding properties and
The properties of the data source. More interesting is that we bind several different controls from a data source. Similarly, I can also bind multiple data sources to different control properties. We can use simple data binding code. Create a lot of complex support interfaces. For example: Use the above example, we bind a SAVE button's enabled attribute to a Business object's isvalID property. This button control is valid when the object is ready to save. .
Remember this data binding is not straight, not only data from the object is displayed on the window, and the user's change is automatically returned automatically. These are all occurred when the user browsing each area, for example: when the control When the focus is lost, our user changes the value of the value of the TXTID control. This data is updated to the object, which is implemented by the set property. We don't need other data binding operations, the system passes its properties Automatically obtain data.