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


相关推荐

  • oracle中varchar和char的区别_char跟varchar

    oracle中varchar和char的区别_char跟varchar1.varchar2把所有字符都占两字节处理(一般情况下),varchar只对汉字和全角等字符占两字节,数字,英文字符等都是一个字节;2.VARCHAR2把空串等同于null处理,而varchar仍按照空串处理;3.VARCHAR2字符要用几个字节存储,要看数据库使用的字符集,大部分情况下建议使用varchar2类型,可以保证更好的兼容性。注意:在oracle中varchar2的最大长…

    2025年7月24日
    10
  • 同一界面画出多个QQ图(R语言)「建议收藏」

    同一界面画出多个QQ图(R语言)「建议收藏」题目:一名研究者用光子吸收法测量了妇女骨骼中无机物含量,对三根骨头主侧和非主侧记录了测量值,数据框“T1bones.txt”中的第2至第7列记录了相应数据。对各个变量做qq图,在同一个界面画出所有的qq图,不同的qq图用不同颜色表示。文件:T1bones.txt受试者编号    主侧桡骨    桡骨    主侧肱骨    肱骨    主侧尺骨    尺骨1    1.103    1….

    2022年8月10日
    10
  • Java API 1.8 中文版 免费下载

    Java API 1.8 中文版 免费下载JavaAPI1.8中文版免费下载无意中淘到的希望对大家有帮助!在这里免费分享给大家百度云盘链接提取码y6wo

    2022年7月26日
    10
  • C# Dictionary通过Value找Key[通俗易懂]

    C# Dictionary通过Value找Key[通俗易懂]Dictionary<string,string>ActiveName=newDictionary<string,string>();for(inti=0;i<10;i++){ActiveName.Add(“”,””);}stringa=””;intindexSARFKSCIActive=ActiveName.Values.ToList().IndexOf(strValue);if(indexSARFKSCIActive>=0

    2022年7月23日
    41
  • 网络抓包工具哪个好_常见抓包工具

    网络抓包工具哪个好_常见抓包工具点击上方“民工哥技术之路”选择“星标”每天10点为你分享不一样的干货一、概述无论是开发还是测试,在工作中经常会遇到需要抓包的时候。本篇博客主要介绍如何在各个平台下,高效的抓包。目前的抓包软件总体可以分为两类,一种是设置代理抓取http包,比如Charles、mitmproxy这些软件。另一种是直接抓取经过网卡的所有协议包,其中最出名就是大名鼎鼎的wireshark以及linux自带的抓包软件tcp…

    2022年4月20日
    35
  • IE中出现 “Stack overflow at line“ 错误的解决方法

    IE中出现 “Stack overflow at line“ 错误的解决方法IE中出现”Stackoverflowatline”错误的解决方法

    2022年7月15日
    13

发表回复

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

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