BindingNavigator 类

BindingNavigator 类v/:*{behavior:url(#default#VML);}o/:*{behavior:url(#default#VML);}w/:*{behavior:url(#default#VML);}.shape{behavior:url(#default#VML);}Normal002

大家好,又见面了,我是你们的朋友全栈君。rel=”File-List” href=”file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml”> rel=”Edit-Time-Data” href=”file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_editdata.mso”>

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

BindingNavigator 类

BindingNavigator 类 备注

BindingNavigator 控件表示在窗体上定位和操作数据的标准化方法。多数情况下,BindingNavigator 与 BindingSource 控件成对出现,用于浏览窗体上的数据记录,并与它们交互。在这些情况下,BindingSource 属性被设置为作为数据源的关联 System.Windows.Forms..::.BindingSource 组件。

默认情况下,BindingNavigator 控件的用户界面 (UI) 由一系列 ToolStrip 按钮、文本框和静态文本元素组成,用于进行大多数常见的数据相关操作(如添加数据、删除数据和在数据中导航)。每个控件都可以通过 BindingNavigator 控件的关联成员进行检索或设置。类似地,还与以编程方式执行相同功能的 BindingSource 类的成员存在一一对应关系,如下表所

UI 控件

BindingNavigator 成员

移到最前

MoveFirstItem

前移一步

MovePreviousItem

当前位置

PositionItem

计数

CountItem

移到下一条记录

MoveNextItem

移到最后

MoveLastItem

新添

AddNewItem

删除

DeleteItem

BindingNavigator 控件添加到窗体并绑定到数据源(例如 BindingSource)时,将自动在此表中建立关系。

可使用以下方法之一自定义此工具栏:

  • 创建带有 BindingNavigator(Boolean) 构造函数的 BindingNavigator,此构造函数接受 Boolean 型的 addStandardItems 参数,并将此参数设置为 false。然后将需要的 ToolStripItem 对象添加到 Items 集合。
  • 如果需要进行大量的自定义设置,或者将重复使用自定义设计,应从 BindingNavigator 派生一个类并重写 AddStandardItems 方法以定义附加标准项或替换标准项。

BindingNavigator 类  示例

下面的代码示例演示如何使用 BindingNavigator 控件浏览数据集。该集包含在 DataView 中,该类已通过 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(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 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());
    }
}

 



版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/158036.html原文链接:https://javaforall.net

(0)
上一篇 2022年7月12日 下午12:00
下一篇 2022年7月12日 下午12:00


相关推荐

  • 单点登录原理与简单实现(单点登录原理与简单实现)

    单点登录(SingleSignOn),简称为SSO,是目前比较流行的企业业务整合的解决方案之一。SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。以下是个人查询资料的借鉴及对接某大型互联网公司单点系统后的一个总结和理解一、首先了解下单系统登录机制1、http无状态协议  web应用采用browser/server架构,http作为通信协议。http是无状态协…

    2022年4月11日
    47
  • 原创腾讯重磅官宣!QQ全面接入“小龙虾”,全民养虾时代来了

    原创腾讯重磅官宣!QQ全面接入“小龙虾”,全民养虾时代来了

    2026年3月13日
    2
  • 怎么用 OpenClaw 搭建 7×24 小时零代码企业级 AI 智能客服机器人?2026 实战部署指南

    怎么用 OpenClaw 搭建 7×24 小时零代码企业级 AI 智能客服机器人?2026 实战部署指南

    2026年3月13日
    2
  • FPGA设计编程(四) 有限状态机设计

    FPGA设计编程(四) 有限状态机设计目录 实验要求 实验软件工具 实验一 设计一个交通红绿灯控制器模块 实现主干道和支路之间红绿黄灯的信号转换 1 实验内容与原理说明 2 实验模块程序代码和激励代码 1 设计模块代码 2 激励模块代码 3 波形仿真图 4 门级电路图 实验二 设计一个小轿车尾灯控制器模块 以书中的例子 1 实验内容与原理说明 2 实验模块程序代码和激励代码 1 设计模块代码 2 激励模块代码 3 波形仿真图 4 门级电路图 实验三 设计一个 10 层楼的电梯控制器模块 1 实验内容与原理说明 2 实验模块程序代码和激励

    2026年3月17日
    1
  • strlen函数用法举例(strlen字符串)

    strlen(char*)函数求的是字符串的实际长度,它求得方法是从开始到遇到第一个’\0’,如果你只定义没有给它赋初值,这个结果是不定的,它会从aa首地址一直找下去,直到遇到’\0’停止。charaa[10];cout<charaa[10]={‘\0’};cout<charaa[10]=”jun”;cout<而sizeof()返回的是变量声明后所占的内存数,不是实际长…

    2022年4月13日
    62
  • WebRTC直播技术方案「建议收藏」

    WebRTC直播技术方案「建议收藏」我们都知道,WebRTC是面向互联网的一种即时通信标准,由于被Chrome、火狐、Safari等主流浏览器支持,并提供了一致和简洁的API,使得开发WebRTC的视频通信应用非常简单和流行。在大多数情况下,我们认为双向视频通信技术和视频直播技术是两种不同的技术,一个做视频通话,一个做单向直播(在以往的直播方案中,绝大部分是采用rtmp协议做直播上行的)。有没有可能使用WebR…

    2022年7月21日
    23

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号