如何调用 bindingNavigator 添加事件

aisililin 2009-12-27 07:58:39
在窗口A中包含一个bindingNavigator控件,点击窗口B中[新增]铵钮调用窗口A,在窗口A的构造函数中调用"bindingNavigator 添加事件",请问如何实现啊,帮帮忙
...全文
219 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
aisililin 2009-12-27
  • 打赏
  • 举报
回复
2楼:您说的方法我试过了,不行,它调用的好像不是Click 事件
aisililin 2009-12-27
  • 打赏
  • 举报
回复
窗口A中有N个textBox,和bindingNavigator绑定了相同的bindingsource,在这些textBox中添加记录内容,然后点击保存来实现添加,现在用户点击了窗口B中的新增后,可以直接向textBox中添加数据,而不用再次点击窗口A中的[+]按钮,所以我想再构造函数中调用bindingNavigator控件中的添加事件,呵呵,现在描述清楚了吧??
aisililin 2009-12-27
  • 打赏
  • 举报
回复
非常感谢大家
Dobzhansky 2009-12-27
  • 打赏
  • 举报
回复
navigator 有 bindingsource
bindingsource 有 addnew 调用

关界面什么事啊,
再说navigator 的新增有木有 CancelEventArgs 可以中止新增的.

如果知道 bindingsource 后面的数据源,

直接在数据源新增也是一样的.
悔说话的哑巴 2009-12-27
  • 打赏
  • 举报
回复
请参考:
http://msdn.microsoft.com/zh-cn/office/2wcswths.aspx
wuyq11 2009-12-27
  • 打赏
  • 举报
回复
this.bindingNavigatorAddNewItem.Click += new System.EventHandler(this.bindingNavigatorAddNewItem_Click);
silentwins 2009-12-27
  • 打赏
  • 举报
回复
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));
}
}

111,121

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧