private void UserList_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'workOrdersDataSet.users' table. You can move, or remove it, as needed.
this.usersTableAdapter.Fill(this.workOrdersDataSet.users);
}
如果以其他形式进行更改,如何重新加载数据? (最好是自动而不使用“刷新”按钮)?
我使用的是WinForms,后端是Access 2007。
使用设计器将数据绑定到数据网格
首先,我将移动Fill
到一个单独的函数:
public void LoadData()
{
this.usersTableAdapter.Fill(this.workOrdersDataSet.users);
}
然后,当您执行加载事件时,您将调用该函数:
private void UserList_Load(object sender, EventArgs e)
{
LoadData();
}
如果您有另一个表单对数据执行更改,则可以在另一个事件中调用此函数,与此类似。我用DialogResult
在我的代码中:
private void OpenOtherForm()
{
DialogResult openForm = new OtherForm().ShowDialog();
if(openForm == DialogResult.OK)
LoadData();
}
更新过程完成后,在另一个表单的代码中,包含一行代码来告诉您的主表单进行更新:
private void PerformUpdate()
{
try
{
// your update code goes here
DialogResult = DialogResult.OK; // this is the line that tells your other form to refresh
}
catch (Exception ex)
{
DialogResult = DialogResult.Abort;
}
}
使用DialogResult
然后,告诉您的主窗体仅在实际发生更新时才触发数据刷新。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)