This quick start guide will walk you through the steps of creating a True DBGrid for WinForms application, binding the grid to a data source, and customizing the grid's appearance and behavior settings. You'll discover that you can easily create powerful database applications using True DBGrid for WinForms.
The quick start uses an Access database, C1NWind.mdb. The C1NWind.mdb database file is located in the Common subdirectory of the WinForms Edition program, the Documents\ComponentOne Samples\Common directory.
Create a new Windows Forms application.
Add reference to C1.Win.TrueDBGrid NuGet package. Drag and drop the TrueDBGrid control from Toolbox to the form. Click 'Dock in Parent Container' option from the C1TrueDBGrid tasks menu.
Create a sample datasource class 'DataSource'.
Bind the True DBGrid to this datasource using the DataSource property of the C1.Win.TrueDBGrid.BaseGrid.Frame class. This will populate the True DBGrid control with data.
C# |
Copy Code
|
---|---|
//bind to data source var data = C1.DemoData.DataSource.GetRows("Select * from Data"); c1TruedbGrid1.DataSource = data; |
You can also customize the grid using the Caption, AllowAddNew, AlternatingRows and EvenRowStyle properties.
C# |
Copy Code
|
---|---|
//customize TrueDbGrid c1TruedbGrid1.Caption = "Data"; c1TruedbGrid1.AllowAddNew = true; c1TruedbGrid1.AlternatingRows = true; c1TruedbGrid1.EvenRowStyle.BackColor = Color.LightBlue; |
Run the code and observe the output:
This section demonstrates how to create a TrueDBGrid application in .NET Framework by binding it to an external datasource using the TrueDBGrid Tasks menu. We will also learn how to customize the grid application using the Tasks menu.
You've successfully created a simple grid application. In the next step, you'll learn how to bind the C1TrueDBGrid control to a data source.
C# |
Copy Code
|
---|---|
this.composerTableAdapter.Fill(this.c1NWindDataSet.Composer); |
Notice that the data from the Composers table is reflected in the grid:
True DBGrid retrieves the database schema information from the DataSet and automatically configures itself to display all of the fields contained in the database table. Note that the field names are used as the default column headings.
Congratulations, you have successfully completed binding a C1TrueDBGrid control to a DataSet. In the next section you will customize the C1TrueDBGrid control's appearance and behavior settings.
You've customized the C1TrueDBGrid control. Notice that you've changed the appearance of the grid and can now add and edit the grid's content.