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。
使用设计器将数据绑定到数据网格
发布于 2012-05-02 04:12:58
首先,我将把Fill移到一个单独的函数中:
public void LoadData()
{
this.usersTableAdapter.Fill(this.workOrdersDataSet.users);
}然后,在执行Load事件时,您将调用以下函数:
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,告诉您的主窗体仅在实际发生更新时触发数据刷新。
发布于 2012-05-02 03:40:59
您可以将此行添加到另一个函数中,例如
public void MoveDataToUI()
{
this.usersTableAdapter.Fill(this.workOrdersDataSet.users);
}然后从even处理程序调用此函数,当有人以另一种形式更改某些内容时会引发该函数。
Events tutorial
https://stackoverflow.com/questions/10403150
复制相似问题