O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating DataGridView dynamically

DataGridView is a good control to display data in a tabular form. However, creating it without using the designer is difficult. In this recipe we will look at how to create DataGridView dynamically and assign a data source to it.

How to do it...

Implementation of DynamicDataGrid and its usage can be performed using the following steps:

  1. Launch Visual Studio 2012. Create a project of type Class Library and name it CookBook.Recipes.WindowForms.DataGrid. Name the solution DynamicDataGrid.
  2. Add a new folder to the project and name it Entities.
  3. Add a new class to the Entities folder and name the class DataGridEntity.
  4. Make the DataGridEntity class public, as shown in the following code snippet:
    public class DataGridEntity { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required