BindingNavigator 类 - MSDN
来源:互联网 发布:gm3188写频软件 编辑:程序博客网 时间:2024/06/05 22:48
注意:此类在 .NET Framework 2.0 版中是新增的。
表示窗体上绑定到数据的控件的导航和操作用户界面 (UI)。
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)
语法
[ComVisibleAttribute(true)] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] public class BindingNavigator : ToolStrip, ISupportInitialize
/** @attribute ComVisibleAttribute(true) */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ public class BindingNavigator extends ToolStrip implements ISupportInitialize
ComVisibleAttribute(true) ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) public class BindingNavigator extends ToolStrip implements ISupportInitialize
备注
BindingNavigator 控件表示在窗体上定位和操作数据的标准化方法。多数情况下,BindingNavigator 与 BindingSource 控件成对出现,用于浏览窗体上的数据记录,并与它们交互。在这些情况下,BindingSource 属性被设置为作为数据源的关联System.Windows.Forms.BindingSource 组件。
默认情况下,BindingNavigator 控件的用户界面 (UI) 由一系列 ToolStrip 按钮、文本框和静态文本元素组成,用于进行大多数常见的数据相关操作(如添加数据、删除数据和在数据中导航)。每个控件都可以通过 BindingNavigator 控件的关联成员进行检索或设置。类似地,还与以编程方式执行相同功能的 BindingSource 类的成员存在一一对应关系,如下表所示。
UI 控件
BindingNavigator 成员
BindingSource 成员
移到最前
MoveFirstItem
MoveFirst
前移一步
MovePreviousItem
MovePrevious
当前位置
PositionItem
Current
计数
CountItem
Count
移到下一条记录
MoveNextItem
MoveNext
移到最后
MoveLastItem
MoveLast
新添
AddNewItem
AddNew
删除
DeleteItem
RemoveCurrent
将 BindingNavigator 控件添加到窗体并绑定到数据源(例如 BindingSource)时,将自动在此表中建立关系。
BindingNavigator 的所有构造函数都调用 AddStandardItems 方法以将标准的 UI 控件集与导航工具栏关联起来。可使用以下技术之一自定义此工具栏:
创建带有 BindingNavigator(Boolean) 构造函数的 BindingNavigator,此构造函数接受 Boolean 型的 addStandardItems 参数,并将此参数设置为 false。然后将需要的 ToolStripItem 对象添加到 Items 集合。
如果需要进行大量的自定义设置,或者将重复使用自定义设计,应从 BindingNavigator 派生一个类并重写 AddStandardItems 方法以定义附加标准项或替换标准项。
示例
下面的代码示例演示如何使用 BindingNavigator 控件浏览数据库查询结果。结果集包含在 DataSet 中,用 BindingSource 组件将它绑定到 TextBox 控件。
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(); // 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 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"; SqlConnection connection = new SqlConnection(); connection.ConnectionString = connectString; connection.Open(); // Execute the query. SqlCommand command = new SqlCommand( "Select * From Customers", connection); SqlDataReader reader = command.ExecuteReader( CommandBehavior.CloseConnection); // Load the Customers result set into the DataSet. DataSet ds = new DataSet("Northwind Customers"); ds.Load( reader, LoadOption.OverwriteChanges, new string[] { "Customers" }); // Assign the DataSet as the DataSource for the BindingSource. this.customersBindingSource.DataSource = ds; // Bind the CompanyName field to the TextBox control. this.companyNameTextBox.DataBindings.Add( new Binding("Text", this.customersBindingSource, "CompanyName", true)); }}
继承层次结构
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ToolStrip
System.Windows.Forms.BindingNavigator
线程安全
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0请参见
参考
BindingNavigator 成员System.Windows.Forms 命名空间
BindingSource
其他资源
BindingNavigator 控件(Windows 窗体)- BindingNavigator 类 - MSDN
- BindingNavigator 类
- .NET Framework 类库BindingNavigator 类
- BindingSource BindingNavigator
- BindingNavigator控件
- BindingNavigator 的继承问题
- bindingNavigator 与textbox 联动
- BindingNavigator与DataGridView绑定
- 关于bindingsource和BindingNavigator
- bindingNavigator的使用
- Enum 类(MSDN)
- FormattedText 类(MSDN)
- msdn
- MSDN
- msdn
- mSDN
- msdn
- MSDN
- 关于调用android4.4系统的图片与剪切版的黑边问题
- 朵拉影像开发日记 12.02
- 初学Perl 用Perl解决了自己的小问题
- 高宏-感知大数据获取与计算
- Java编写简单客户/服务器程序
- BindingNavigator 类 - MSDN
- Domino实现外网邮件转发功能配置
- Problem E: Matrix Problem : Array Practice
- Android Studio 快捷键整理分享-SadieYu
- Android 屏幕适配
- java多线程之其他知识简介
- UVA - 10010 Where's Waldorf?
- UART与COM口之区别
- Java 理论与实践: 处理 InterruptedException