New to Telerik UI for WinForms? Download free 30-day trial

Getting Started with WinForms GridView

RELATED VIDEOS
RadGridView for WinForms Webinar
Lino Tadros from Falalel provides an in-depth overview of Telerik's RadGridView for WinForms (Runtime: 01:45:11)

The following tutorial demonstrates how to create a hierarchical grid that presents two tables: Product Category and Product Information.

Figure 1: The final result

WinForms RadGridView Hierarchical Grid With Two Table

Setting up the Form

  1. Create a new Windows Forms Application project.

  2. Drop a RadGridView control on the form.

  3. In the Properties window for RadGridView, set the RadGridView.Dock property to Fill.

Connecting to Data

  1. In the Properties window for RadGridView, locate the DataSource property drop-down.

  2. Select Add Project Data Source. This step will open the Data Source Configuration Wizard.

  3. On the Choose a Data Source Type page, select Database and click Next. WinForms RadGridView Choose a Data Source Type

  4. On the Choose a Database Model page, select Dataset.

  5. On the Choose Your Data Connection page, select New Connection.... This page displays the Choose Data Source dialog.

  6. In the Choose Data Source dialog, select Microsoft Access Data Base File.

  7. Click Continue.

  8. In the Add Connection dialog, click the Browse... button. This step will display the Select Microsoft Access Database File dialog.

  9. In the Select Microsoft Access Database File dialog, navigate to the Telerik UI for WinForms installation directory and locate the Nwind.mdb file within the \Examples\QuickStart\Datasources directory. Select Nwind.mdb and click OK.

  10. Click OK again to close the Add Connection dialog.

  11. On the Choose Your Data Connection page, click Next. Visual Studio shows a dialog that asks if you want to copy the file to your project.

  12. Click Yes to close the Visual Studio dialog.

  13. On the Save the Connection String to the Application Configuration File page, click Next.

  14. On the Choose Your Database Objects page, expand the Categories table.

  15. Select the following columns in the Categories table: CategoryID, CategoryName and Description.

  16. Expand the Products table and select the following columns: ProductName, CategoryID, UnitsOnOrder and Discontinued.

    WinForms RadGridView Select Columns

  17. Click Finish to close the Data Source Configuration Wizard.

  18. In the Properties window for RadGridView, select the DataSource property drop-down.

  19. Locate the NwindDataSet data source.

  20. Select Categories from the NwindDataSet data source. This step will create the categoriesBindingSource and categoriesTableAdapter components.

    WinForms RadGridView Select Categories

  21. Select the DataSource property drop-down for a second time.

  22. Select Products from the NwindDataSet data source. This step will create the productsBindingSource and productsTableAdapter components.

  23. Select the DataSource property drop-down for a third time.

  24. Select NwindDataSet. This step will assign the entire data set to the grid.

    WinForms RadGridView NwindDataSet

Setting Properties

  1. In the Properties window for RadGridView, select the DataMember property.

  2. Select Categories from the drop-down list. This step will assign Categories as a top level table for the grid.

  3. In the Properties window for RadGridView, select the AutoGenerateHierarchy property.

  4. Select True from the drop-down list.

  5. Click the RadGridView smart tag in the form.

  6. Select Open Property Builder from the smart tag menu.

  7. Select the CategoryID column in the navigation tree and clear the checkbox.

  8. Click OK to close the Property Builder.

  9. Press F5 to run the application. Notice that the grid displays the product categories first. Each category has an icon that you can click to expand that category and show a child template with the corresponding products.

See Also

Telerik UI for WinForms Learning Resources

In this article