Tutorial of Data Grid Controls
The DataGrid Controls for Windows Forms applications are an amazing component for design modern user interface. This cool control provides large flexibility to meet any critical requirements of applications nowadays. Furthermore, the DataGrid View control also provides data presentation, data refresh, data entry, data analysis, codeless development and hardcore coding functionalities. The following is a C# tutorial that shows how to create gird in Windows Forms project to present tables.
How to Add Data Grid Control to Windows Forms
- Open your existing Windows Forms project or create a new one.
- Drag the Kettic Data Grid Control from the toolbox and drop on the form you are building
How to Bind Grid Control to Data
- Open the Properties window, choose the DataSource property and open its drop down list, expand the Add Project Data Source
- After the Data Source Configuration Wizard appear, select a data source and click database icon, and hit Next
- Open the Add connection dialog by choosing New Connection button in the Choose Your Data Connection wizard, and select the Change button to show the Change Data Source dialog
- Choose Microsoft Access Data Base File from the data source list and click OK button to close the dialog
- Click Browse button in the Add Connection dialog to show the Select Microsoft Access Database File dialog.
- And then navigate to the Kettic UI WinForms Controls and add the Northwind.mdb file from the location, \Kettic\Samples\Datasources directory, and click OK to close the dialog
- Copy the data file to your project in Choose Your Data Connection page of the wizard, and then close the dialog
- Click the Next button in Save the Connection String to the Application Configuration File wizard
- Choose data objects for columns from Classes table, ClassID, ClassName, Details, and columns from Product table, ProductName, ClassID, NumberOfOrder. And then click Finish button to close the Data Source Configuration Wizard.
- Open the DataSource property drop down in the Properties window, and choose Classes and Products from the Northwind data source to bind the grid control to data.
- Choose the Northwind data set in the DataSource property drop down to assign the dataset to the grid.
Properties Configuration of Grid Control
- Configure the DataMember property in the Properties window to assign Classes table as a top level for the grid
- Enable the AutoGenerateHierarchy property and choose Open Property Builder from Grid View smart tag.
- Cancel the selected ClassesID checkboxed in Property Builder Structure pane and close the Property Builder window.
- Run the Grid Windows application to see the result.