BindingNavigator 类 - MSDN

article/2025/8/24 8:07:34
.NET Framework 2.0
其他版本
5(共 9)对本文的评价是有帮助 评价此主题

注意:此类在 .NET Framework 2.0 版中是新增的。

表示窗体上绑定到数据的控件的导航和操作用户界面 (UI)。

命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)

语法

C#
C++
VB
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class BindingNavigator : ToolStrip, ISupportInitialize
J#
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class BindingNavigator extends ToolStrip implements ISupportInitialize
JScript
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 控件。

C#
C++
VB
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.Object 
    System.MarshalByRefObject 
      System.ComponentModel.Component 
        System.Windows.Forms.Control 
          System.Windows.Forms.ScrollableControl 
            System.Windows.Forms.ToolStrip 
             System.Windows.Forms.BindingNavigator

线程安全

此类型的任何公共静态(Visual Basic 中的  Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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 窗体)

http://chatgpt.dhexx.cn/article/2LrK08B5.shtml

相关文章

Android的一个BindView工具的实现

对于Android已经有很多Bind View的工具了,大多都是使用了反射和注解的方法。那么如何实现一个简易的代码生成工具呢?其实不难,只要会写代码都可以试试。这些天,我试了一下,并将它做成了工具。代码如下: pa…

setNavigationBarTitle

wx.setNavigationBarTitle就是用来改红框框里面的内容滴 在项目开发中经常用到 使用的场景就包括了多个地方用同一套页面的时候 wx.setNavigationBarTitle({title: "我的店铺",});

安卓ViewBinding详解

背景 之前我们通过Kotlin Android Extensions来访问布局文件中的元素,但是这个现在被废弃了,原因如下: 空安全:res下的任何id都可以被访问,有可能因访问了非当前Layout下的id而出错兼容性:只能在kotlin中…

Winform中用bindingNavigator和bingdingSource实现分页

BindingNavigator控件介绍 可以使用BindingNavigator控件来创建标准化的方法,以便用户搜索和更改 Windows 窗体上的数据。BindingNavigator 控件由包含一系列 ToolStripItem 对象的ToolStrip组成,可以实现:添加数据,删除数据&…

DataGridView使用bindingNavigator实现分页功能(应用存储过程)

想法是这样的:使用bindingNavigator存储过程实现DataGridView的分页功能,其中包含简单的查询。 存储过程如下: --创建分页查询存储过程(含输出参数,输入参数(含搜索功能)) use HotelDB if exists(select *…

配置bind

安装bind yum install bind-* service firewalld stop #暂时关闭防火墙 vim /etc/named.conf Linsten-on port 53 {any;}; 监听除了自己以外的ip Allow-query{any;} 允许任意的ip来访问 配置正向解析 /etc/named.rfc1912.zones #直接在底部添加 zone "s…

Android dataBinding和viewBinding的混淆配置

在最近重构过的项目中有使用dataBinding或viewBinding,在调试的时候没有问题,但是在混淆过后出现了崩溃: 我们知道viewbinding的初始化是ActivityMainBinding.inflate() 而我是通过反射去初始化viewbinding的 很明显,布局所生成的…

viewBinding和@BindView的用法的简单使用

viewBinding 1.module下的build.gradle,在闭包android{ }里面添加 viewBinding {enabled true} 2.使用方法 用视图绑定功能后,系统会为该模块中包含的每个 XML 布局文件生成一个绑定类。这个类的类名是以xml布局文件名去掉下换线后,单词…

BindingNavigator控件

WinForm之中BindingNavigator控件的使用 在微软WinForm中,BindingNavigator控件主要用来绑定数据。可以将一个数据集合与该控件绑定,以进行数据 联动的显示效果。如图下图所示: 那么,下面我们就来用BindingNavigator控件做一下上图…

WinForm控件之【BindingNavigator】【DataSet】【BindingSource】【DataGridView】

基本介绍 数据类控件,数据加载绑定便捷应用相当广泛,具体看例子自行扩展吧; 常设置属性 BindingNavigator--BindingSource:数据来源,绑定后默认项会根据相应的操作按钮执行操作; BindingNavigator--Items&a…

WinForm之中BindingNavigator控件的使用

在微软WinForm中,BindingNavigator控件主要用来绑定数据。可以将一个数据集合与该控件绑定,以进行数据联动的显示效果。如图下图所示: 那么,下面我们就来用BindingNavigator控件做一下上图所示的效果。 分析:该案例以B…

winform控件之BindingNavigator

BindingNavigator控件可以为我们绑定的数据提供一个导航的功能,默认的工具是这个样子的,我们可以根据需求再增加功能 1.BindingNavigator用法 1.1界面布局 界面布局如下 一个BindingNavigator名为bindingNavigator1 一个DataGridView名为DataGridVie…

C#开发之——ToolStrip(10.22)

一 概述 在C# WinForm开发中添加工具栏(ToolStrip)和添加菜单栏类似&#xff0c;在工具箱中将ToolStrip控件直接拖到Windows窗体中即可 <!--more--> 二 ToolStrip操作 从工具箱拖拽ToolStrip控件到Windows窗体后&#xff0c;如下图所示(在添加了ToolStrip控件之后&…

C#winform窗体控件之toolStrip

C#winform窗体控件之toolStrip 在做窗体时我们可能需要一个工具栏&#xff0c;那这时最简单的方法就是添加一个toolStrip控件。 如何完成一个上图的工具栏呢? 首先&#xff0c;需要添加一个toolStrip控件&#xff0c;然后点击控件上的添加按钮&#xff0c;添加你需要的控件&…

C#如何让ToolStrip工具栏按钮分别靠左和靠右对齐分布

ToolStrip工具栏按钮默认靠左对齐&#xff0c;如何让ToolStrip工具栏按钮分别靠左和靠右对齐分布&#xff1f;&#xff01; 第一步&#xff0c;选择要靠右对齐的工具栏上的按钮&#xff0c;属性&#xff0c;设置“Alignment: Right” 即&#xff0c;this.toolStripSysInfoBut…

ToolStrip

&#xfeff;&#xfeff; 效果实现&#xff1a; 1.添加ToolStrip控件 2.点击ToolStrip控件添加button,设置Imagine,对ToolStripButton的Text进行设置,DisplayStyle设置为ImagineAndText即可。

ToolStrip控件中如何添加功能按钮

1&#xff0c;在工具箱中选择ToolStrip控件 2&#xff0c;在属性框&#xff0c;选择item 3,进入该界面&#xff0c;选择添加类型 4&#xff0c;指定选定控件的类型 name:控件的名字&#xff0c;相当于对象名。 text&#xff1a;指定控件中内容限制字段 image&#xff1a;指…

c# ToolStrip控件图片和文字显示

如上图达到这样的效果 首先我们给属性Image和Text分别赋予需要显示的图片和文字 然后设置DisplyStyle属性为ImageAndText&#xff0c;意为同时显示图片和文字 各种设置ImageAlign和TextAlign&#xff0c;调整图片和文字的位置 设置ImageTextRelation属性&#xff0c;获取或…

C# toolstrip按钮的图片不显示

toolstrip按钮的图片不显示 一、设置图片尺寸异常无法正常显示出图片。 以为没正常设置toolStrip尺寸照成图片无法正常显示的效果&#xff0c;如下图&#xff1a; 修改为正常尺寸后可以正常先显示图图片 显示正常 二、按钮没有选择图片显示模式&#xff0c;DisplayStyle:No…