Version

Binding WinGrid to a Flat Data Source

This topic is designed to get you up and running as quickly as possible by describing the minimum basic procedure for adding the WinGrid™ to a form in Visual Studio .NET. This procedure shows you how to add the WinGrid control to a Visual Studio .NET project and bind it to a flat data source.

To bind the WinGrid control to a flat data source:

  1. Create a new Windows Application.

  2. Select the UltraGrid control in your toolbox and draw the control on the form. The UltraGrid Designer displays. Click Finish to close the dialog box.

  3. In the Properties window, select the WinGrid’s DataSource property to display the drop-down list. In the drop-down list, click the "Add Project Data Source…​" link.

datasource add project data source drop down
  1. The Data Source Configuration Wizard appears. This wizard will aid you in connecting to a Database, Web Service, or Object. Select Database and click Next.

  2. In the Choose Your Data Connection dialog box, click New Connection. The Add Connection dialog box appears, which will allow you to navigate out to the location of your database. For this example, we will be using the Northwind database (NWind.mdb), which is available as part of the Infragistics Professional SDK install. By default, the NWind.mdb file is located in the following installation folder, depending on your operating system:

    • Windows 7 — C:\Users\Public\Documents\Infragistics\2020.1\Windows Forms\Samples\Legacy\Data

    • XP — C:\Documents and Settings\All Users\Documents\Infragistics\2020.1\Windows Forms\Samples\Legacy\Data

    • Vista — C:\Users\Public\Documents\Infragistics\2020.1\Windows Forms\Samples\Legacy\Data

Click Browse…​ to navigate out to the installation path, and select the NWind.mdb file. The Add Connection dialog box should look similar to the following. When you have the connection established, click OK.

Add connection dialog box
  1. In the Choose Your Data Connection dialog box, click Next. A message box will appear explaining that the data file you have chosen is not in the current project, and gives you the option to copy the data file to your project. Click Yes.

  2. The next dialog wants to know if you wish to save your connection string used to access the data file in your application configuration file. Click Yes, as we are only connecting to the NWind.mdb file, so security isn’t an issue here.

  3. In the Choose Your Database Objects dialog box, expand the Tables node and select the Customers table. Then, click Finish.

bind ultragrid to a flat data source
  1. A dataset, BindingSource, and TableAdapter will be generated and added as components for your form. WinGrid also will show the columns that will be shown when WinGrid is rendered.

  2. Go to your code-behind file, and you will see the form’s Load event has been wired, and the following code is inside the event. This code fills the dataset using the TableAdapter that was generated.

In Visual Basic:

Me.CustomersTableAdapter.Fill(Me.NWindDataSet2.Customers)

In C#:

this.customersTableAdapter.Fill(this.nWindDataSet2.Customers);
  1. Run the application. You will see the WinGrid control on the form filled with the data from the Customers table.