对于被绑定的数据库表,如何每当到了一个记录时,调用一个处理子程序或事件? 50分

BCB 2004-12-24 02:11:22
当前记录到了那条记录,就调用一个子程序或事件处理一下,用什么事件呢
...全文
103 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
BCB 2004-12-30
  • 打赏
  • 举报
回复
人气这么不足呀,这C#没人会?!
BCB 2004-12-29
  • 打赏
  • 举报
回复
欢迎继续讨论这个问题,分会再加的!
BCB 2004-12-29
  • 打赏
  • 举报
回复
不错,谢了。
1。绑定基事件Position_Changed()第一条记录不引起事件,因为记录号变了才发生事件的,
解决这个问题很简单,初始时,自已先调用一次这个事件;不过有没有其它解决办法;
2。有dataGrid时遇到点麻烦,我这个dataGrid1是放在TabControl1中另一个tabPage5中的,
如果不去这个tabPaghe5看一dataGrid1,这个Position_Changed()就是不执行,虽然在
textBox1中看到记录变化,除非去看一下dataGrid1
private void Form1_Load(object sender, System.EventArgs e)
{
oleDbConnection1.Open();
oleDbDataAdapter1.Fill(dataSet1);
DataTable table=dataSet1.Tables[0];
dataGrid1.DataSource=table;
textBox1.DataBindings.Add("Text",table,"姓名");


BindingManagerBase bm =
this.BindingContext [table];

// Add the delegate for the PositionChanged event.
bm.PositionChanged += new EventHandler(Position_Changed);
}
private void Position_Changed(object sender, EventArgs e)
{
// Print the Position property value when it changes.
int p=((BindingManagerBase)sender).Position;
statusBar1.Panels[0].Text=p.ToString();
}

private void button1_Click(object sender, System.EventArgs e)
{
DataTable table=dataSet1.Tables[0];
this.BindingContext [table].Position++; // 上一条记录
}

private void button2_Click(object sender, System.EventArgs e)
{
DataTable table=dataSet1.Tables[0];
this.BindingContext [table].Position--;  // 下一条记录
}
yhec 2004-12-29
  • 打赏
  • 举报
回复
up
marvelstack 2004-12-28
  • 打赏
  • 举报
回复
BindingManagerBase.PositionChanged 事件
============================================
protected void BindControl()
{
/* Create a Binding object for the TextBox control.
The data-bound property for the control is the Text
property. */
Binding myBinding =
new Binding("Text", ds, "customers.custName");

text1.DataBindings.Add(myBinding);

// Get the BindingManagerBase for the Customers table.
BindingManagerBase bmCustomers =
this.BindingContext [ds, "Customers"];

// Add the delegate for the PositionChanged event.
bmCustomers.PositionChanged +=
new EventHandler(Position_Changed);
}

private void Position_Changed(object sender, EventArgs e)
{
// Print the Position property value when it changes.
Console.WriteLine(((BindingManagerBase)sender).Position);
}
BCB 2004-12-28
  • 打赏
  • 举报
回复
嫌分少?!
BCB 2004-12-27
  • 打赏
  • 举报
回复
其实我只想将当前记录号显示在状态栏,就是说每当改变了当前
记录,状态栏就显示记录号,需要一个事件,每当当前记录移动了,
事件发生了,就在状态栏显示记录号,
什么事件能满足这个条件呢?
BCB 2004-12-25
  • 打赏
  • 举报
回复
没高手?
yhec 2004-12-25
  • 打赏
  • 举报
回复
up
yhec 2004-12-24
  • 打赏
  • 举报
回复
GZ

110,534

社区成员

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

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

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