Use the setdatabinding method to set the datasource and datamember attributes at runtime.
The following data sources are valid:
L datatable
L dataview
L Dataset
L dataviewmanager
L any component that implements the ilistsource Interface
L any component that implements the ilist Interface
If datasource references more than one table, you must set a string to the datamember attribute, which specifies the table to bind. For example, if datasource is a dataset or dataviewmanager that contains three tables: MERs, orders, and orderdetails, you must specify the table to bind.
Setting datasource to an object that does not implement the ilist interface or an ilistsource will cause grid exceptions.
By using dataview as a data source and setting the addnew attribute to false, you can create a grid that allows users to edit data but prevent them from adding new rows.
To bind a DataGrid to a strong array of objects, the object must contain public attributes. To create a datagridtablestyle that displays such arrays, set the mappingname attribute to classname [], where classname will be replaced by the class name. Note that the mappingname attribute must be case sensitive.
You can also bind the DataGrid to the arraylist. One feature of arraylist is that it can contain multiple types of objects, but when all items in the list have the same type as the first item, the DataGrid can only be bound to this type of list. This means that all objects must be of the same type, or must be inherited from the first class in the list. For example, if the first item in the list is control, the second item may be Textbox (which inherits from control ). On the other hand, if the first item is Textbox, the second object cannot be control. In addition, arraylist must contain items when binding. Empty arraylist results in empty mesh. When binding to arraylist, set datagriingname of the datagridtablestyle to "arraylist" (type name ).