Windows Forms: Metro GridView in C#

This post shows how you how to use metro gridview with metro framework c#, then use entity framework to retrieve data from sql database in c# windows forms application.

Metro Framework is an open source library using c# ui framework that helps you design a modern awesome ui.

To play the demo, you should create a new windows forms application project, then right click on your project and select Manage NuGet Packages -> Search metro framework -> Install it on your project.

If you don't see the metro framework toolbox, you can view How to download and install metro framework

Drag the MetroLabel, MetroTextbox, MetroGridView and MetroButton controls from the visual studio toolbox to your window form, then create a simple metroframework modern ui sample project as shown below.

c# metro gridview

Next, Right click on your project select Add -> New Item -> ADO.NET Entity Data Model -> Select Northwind database -> Products table.

If you haven't got Northwind database, you can view How to download and restore Northwind database in SQL Server

To create metro or modern ui style windows application in c#. You need to change the inheritance from the Form to the MertroForm, then add code to initialize your MetroStyle as shown below allows you to apply metro framework change theme.

public Form1()
{
    InitializeComponent();
    //Init theme, style
    this.StyleManager = metroStyleManager1;
    metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Light;
    metroStyleManager1.Style = MetroFramework.MetroColorStyle.Green;
}

Add the click event handler to the Load button allows you to retrieve data from the sql database. You should add the BindingSource control to the MetroGridView and TextBox control, then set the DataSource for BindingSource control as the following c# code.

private void btnLoad_Click(object sender, EventArgs e)
{
    using (NorthwindEntities db = new NorthwindEntities())//Create an instance for data context
    {
        productBindingSource.DataSource = db.Products.ToList();
    }
}

VIDEO TUTORIAL