How To Design Datagridview In C# Windows Application
Introduction
The DataGridView command available as a part of Windows Forms controls in Visual Studio 2008 is much more powerful than it'southward previous versions. This tutorial is a bones introduction of how to write a unproblematic information driven application using Visual Studio 2008 wizards without writing a unmarried line of code. In my next articles, I will talk almost more than detailed features of the DataGridView control.
The DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the DataGridView control to show read-just views of a small amount of data, or you can scale it to prove editable views of very big sets of information. This control as well let'south y'all display data in a chief-details view.
With the DataGridView control, you can display and edit tabular data from many different kinds of data sources. Binding data to the DataGridView control is straightforward and intuitive, and in many cases it is as simple as setting the DataSource holding. When you demark to a data source that contains multiple lists or tables, set the DataMember property to a string that specifies the list or table to demark to.
The DataGridView control supports the standard Windows Forms data bounden model, so it volition bind to instances of classes described in the following listing,
- Any course that implements the IList interface, including one-dimensional arrays.
- Any class that implements the IListSource interface, such every bit the DataTable and DataSet classes.
- Whatsoever class that implements the IBindingList interface, such as the BindingList<(Of <(T>)>) class.
- Whatsoever form that implements the IBindingListView interface, such as the BindingSource class.
The DataGridView control supports data binding to the public properties of the objects returned by these interfaces or to the properties drove returned past an ICustomTypeDescriptor interface, if implemented on the returned objects. Typically, you will demark to a BindingSource component and bind the BindingSource component to some other data source or populate it with business objects. The BindingSource component is the preferred data source considering it tin demark to a broad multifariousness of data sources and can resolve many data binding issues automatically.
The DataGridView control tin can likewise be used in unbound mode, with no underlying data store. For a code example that uses an unbound DataGridView control, see Walkthrough: Creating an Unbound Windows Forms DataGridView Command. The DataGridView control is highly configurable and extensible, and it provides many properties, methods, and events to customize its appearance and behavior. When you lot desire your Windows Forms awarding to display tabular data, consider using the DataGridView control earlier others (for example, DataGrid). If you are displaying a modest grid of read-only values, or if you are enabling a user to edit a table with millions of records, the DataGridView command will provide you with a readily programmable, retention-efficient solution.
Getting Started
OK permit'due south get started. Follow these steps and you will run into how to write a data driven application without writing a single line of lawmaking.
Footstep 1
Create a new Windows Forms Application projection in Visual Studio 2008.
Figure 1.
Step 2
Drag and drop DataGridView control from toolbox to form window.
Effigy two.
Step 3
Now choose a data source by right clicking on the DataGridView and and so click on Add Project Information Source. We volition exist adding a new data source to the project right now.
Figure 3.
Step 4
Now select data source type, I am choosing Database in this case.
Later on selecting Database, click adjacent.
Figure 4
Step 5
Choose your information connection, if you already have a connection available select that, otherwise brand new connexion, and follow the steps and afterward that click next.
Figure 5.
Step half dozen
Add Connectedness Wizard.
Figure half dozen
Step 7
Choose y'all database objects, and click next, if you want local database caching and then check enable local database caching cheque box and click next.
Figure vii.
Step 8
Select table for caching.
Figure viii.
Footstep ix
Now your data source is created, right click on DataGridView control and on the choice Cull Data Source, select the data source you just created.
Figure 9.
That'south all. Yous are all prepare.
Now you simply need to add ane line of lawmaking. If your class load event does not take this code allready. add this lawmaking. Otherwise information technology should have information technology.
- private void Form1_Load(object sender, EventArgs e)
- {
- this .vendorTableAdapter.Fill up( this .vendorDataSet.Vendor);
- }
Footstep x
At present build and run the application. Your application looks like the post-obit.
Figure 10.
Summary
In this tutorial, you lot saw how to build a elementary data driven awarding using a DataGridView command in Visual Studio 2008 without writing a single line of code.
More manufactures on DataGridView
- Database Table Update in a DataGridView without Writing Code
- Bind Objects to a DataGridView Control
- Generic DataGridView
- Sorting with DataGridView using C#.
- Host a combo box cavalcade within a DataGridView control
- Creating a Context Bill of fare on a DataGridView Mouse Click
- Import Data from Text and CSV file to DataGridView in .Internet
- Printing the DataGridView
- Convert a DataGridView to a Bitmap
- How to : Add an autonumber column in a DataGridView
- Custom Time Cell in DataGridView
Source: https://www.c-sharpcorner.com/uploadfile/raj1979/datagridview-control-in-C-Sharp/
Posted by: morrisonnotilen.blogspot.com
0 Response to "How To Design Datagridview In C# Windows Application"
Post a Comment