本文整理汇总了C#中System.Windows.Forms.BindingNavigator类的典型用法代码示例。如果您正苦于以下问题:C# BindingNavigator类的具体用法?C# BindingNavigator怎么用?C# BindingNavigator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingNavigator类属于System.Windows.Forms命名空间,在下文中一共展示了BindingNavigator类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BindingNavigator
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;
// This form demonstrates using a BindingNavigator to display
// rows from a database query sequentially.
public class Form1 : Form
{
// This is the BindingNavigator that allows the user
// to navigate through the rows in a DataSet.
BindingNavigator customersBindingNavigator = new BindingNavigator(true);
// This is the BindingSource that provides data for
// the Textbox control.
BindingSource customersBindingSource = new BindingSource();
// This is the TextBox control that displays the CompanyName
// field from the DataSet.
TextBox companyNameTextBox = new TextBox();
public Form1()
{
// Set up the BindingSource component.
this.customersBindingNavigator.BindingSource = this.customersBindingSource;
this.customersBindingNavigator.Dock = DockStyle.Top;
this.Controls.Add(this.customersBindingNavigator);
// Set up the TextBox control for displaying company names.
this.companyNameTextBox.Dock = DockStyle.Bottom;
this.Controls.Add(this.companyNameTextBox);
// Set up the form.
this.Size = new Size(800, 200);
this.Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
// Open a connection to the database.
// Replace the value of connectString with a valid
// connection string to a Northwind database accessible
// to your system.
string connectString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
using (SqlConnection connection = new SqlConnection(connectString))
{
SqlDataAdapter dataAdapter1 =
new SqlDataAdapter(new SqlCommand("Select * From Customers",connection));
DataSet ds = new DataSet("Northwind Customers");
ds.Tables.Add("Customers");
dataAdapter1.Fill(ds.Tables["Customers"]);
// Assign the DataSet as the DataSource for the BindingSource.
this.customersBindingSource.DataSource = ds.Tables["Customers"];
// Bind the CompanyName field to the TextBox control.
this.companyNameTextBox.DataBindings.Add(
new Binding("Text",
this.customersBindingSource,
"CompanyName",
true));
}
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:79,代码来源:BindingNavigator
注:本文中的System.Windows.Forms.BindingNavigator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论