Create a DataTable to bind to DataGridView

Source: Internet
Author: User

private datatable dt = new DataTable ();

BindingSource bs = new BindingSource ();

<summary>
Initializing a DataTable
</summary>
public void initdatatable ()
{

Do not allow automatic generation, if allowed, the interface will automatically increase the DataTable column, then the interface will contain the columns defined in the DataGridView, also contains the DataTable defined columns
This.dataGridView1.AutoGenerateColumns = false;

DataColumn col = new DataColumn ("No", typeof (int));
Dt. Columns.Add (COL);
Dt. Columns.Add (New DataColumn ("Addr", typeof (String)));
Dt. Columns.Add (New DataColumn ("Funtiontype", typeof (String)));
Dt. Columns.Add (New DataColumn ("Result", typeof (String)));

Bs. DataSource = DT;
This.dataGridView1.DataSource = BS;

Data-binding columns in DataGridView to columns in a DataTable, this.clonum as column names

This.colNum.DataPropertyName = "No";
This.colAddress.DataPropertyName = "Addr";
This.colFunction.DataPropertyName = "Funtiontype";
This.colResult.DataPropertyName = "Result";
}

Create a DataTable to bind to DataGridView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.