datagridview如何在改变数据后自动刷新呢
3个回答
2015-07-01 · 知道合伙人互联网行家
关注
展开全部
private void Form1_Load(object sender, EventArgs e)
{
regionTableAdapter1.Fill(northwind1.Region);
bindingSource1.DataSource = northwind1.Region;
bindingSource1.PositionChanged += new EventHandler(bindingSource1_PositionChanged);
dataGridView1.DataSource = bindingSource1;
bindingSource1_PositionChanged(bindingSource1, null);
}
void bindingSource1_PositionChanged(object sender, EventArgs e)
{
try
{
Northwind.RegionRow r = ((bindingSource1.Current as DataRowView).Row as DataRow) as Northwind.RegionRow;
textBox1.Text = r.RegionID.ToString();
textBox2.Text = r.RegionDescription;
}
catch
{
}
}
private void button1_Click(object sender, EventArgs e)
{
Northwind.RegionRow r = northwind1.Region.NewRegionRow();
r.RegionID = int.Parse(textBox1.Text);
r.RegionDescription = textBox2.Text;
northwind1.Region.AddRegionRow(r);
regionTableAdapter1.Update(northwind1.Region);
}
private void button2_Click(object sender, EventArgs e)
{
Northwind.RegionRow r = ((bindingSource1.Current as DataRowView).Row as DataRow) as Northwind.RegionRow;
r.RegionDescription = textBox2.Text;
regionTableAdapter1.Update(northwind1.Region);
}
private void button3_Click(object sender, EventArgs e)
{
Northwind.RegionRow r = ((bindingSource1.Current as DataRowView).Row as DataRow) as Northwind.RegionRow;
r.Delete();
regionTableAdapter1.Update(northwind1.Region);
}
展开全部
如果是winform,就做一个触发器,定时访问数据库看有没有数据变化,如果有变化就重新调用一下这个绑定的过程,timer控件。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.datagridview.databind();这样就可以实现绑定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询