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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • struts2的response的contentType设置

    struts2的response的contentType设置服务器端发送到客户端,提示保存还是打开?       response.setContentType(“text/html;charset=utf-8”)发送到客户端格式不正确。使用ajaxUpload插件的时候,strust2返回application/json格式的数据,但是ajaxUpload要求返回text/html,这样就需要在配置文件中配置contentType项。

    2022年7月19日
    12
  • 一篇读懂:Android手机如何通过USB接口与外设通信(附原理分析及方案选型)

    一篇读懂:Android手机如何通过USB接口与外设通信(附原理分析及方案选型)0背景1.手机USB接口通信特点-1.1使用方便-1.2通用性强-1.3速度快-1.4可采用总线供电2.手机USB接口通信原理-2.1常见手机USB接口-2.2通信过程-2.3体系架构2.4软件层次3.手机USB接口与外设通信方案-3.1USB(手机)USB(外设)-3.1.1USBHost简述

    2022年6月17日
    130
  • Try catch如何使用[通俗易懂]

    Try catch如何使用[通俗易懂]trycatch适用场合:一、兼容性浏览器的兼容性是程序员很头痛的事儿,往往一些出错会让我们查找许久,在使用trycatch能更好的解决兼容性出错的问题:由于不同浏览器报错提示也不尽相同,通过使用trycatch捕获的浏览器的报错提示,来判断用户使用的浏览器,然后做出对应的解决方法;那么,你如果用if,就只能反馈真或假,而不能直接抛出浏览器的报错内容。二、防止阻塞trycatch用…

    2022年6月20日
    43
  • kali 换源教程

    一·寻找终端kali的终端类似于windows的dos,可以在此界面中,对kali系统进行操纵。其位于界面左侧,第三个图标便是终端。二·打开“sources.list“打开kali的终端输入命令“leafpad/etc/apt/sources.list“三·更改“sources.list“界面里所有内容全部删除,添加中科大的源。下面的就是中科大源的地址。debhttps:…

    2022年4月9日
    2.4K
  • Java课程设计—学生成绩管理系统(201521123004-林艺如)「建议收藏」

    Java课程设计—学生成绩管理系统(201521123004-林艺如)「建议收藏」1.团队课程设计博客"团队课程设计博客链接"2.个人负责模块或任务说明①.MenuMenu.jsp在页面中给出提示,用HTML的,与下一个跳转页面进行连接,即点击后进入下

    2022年6月30日
    29
  • C++之内联函数

    C++继承C的一个重要特性是效率,在C中保护效率的一个方法是使用宏(macro),宏的实现是使用预处理器而不是编译器,预处理器直接用宏代码替换宏调用,所以就没有了参数压栈、生成汇编语言的CALL、返回

    2021年12月19日
    50

发表回复

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

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