Access.
In order to bind Data Grid please follow these steps: -
1. Open the TierDeveloper generated project in VS.NET
2. Add and open a new Windows Form.
3. Select the ToolBox window and click on Windows Forms tab.
4. Drag DataGrid component and place it anywhere on the Windows Form.
5. Paste the following code in the Windows Form Load event.
[Visual Basic]
Private Sub CustomersForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cf As CustomersFactory = New CustomersFactory
DataGrid1.CaptionText = "Customers"
DataGrid1.DataSource = cf.GetAllCustomersDS()
End Sub
[C#]
Private void CustomersForm_Load(object sender, System.EventArgs e)
{
CustomersFactory cf = New CustomersFactory();
DataGrid1.CaptionText = "Customers" ;
DataGrid1.DataSource = cf.GetAllCustomersDS();
}
6. The postfix DS shows that this method will return a DataSet object.
7. Run the application and you will see that the DataGrid is filled with all the customers.
Note: You can also bind datagrid to customer collection to do this you will just have to change the grid data source to the method that can return collection.
DataGrid1.DataSource = cf.GetAllCustomers();
About The Author
I am Ann Morris and work in Software development consultancy company.
ann@alachisoft.com