问题描述
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);
}
我怎样才能重新加载数据进行了更改,以另一种形式提出? (最好是自动,而无需使用刷新按钮)?
How can I reload the data if changes were made in another form? (preferably automatically without using a Refresh button)?
我使用的WinForms和后端的Access 2007年。
I am using WinForms and the backend is Access 2007.
数据使用设计器到DataGrid
The data is bound using the Designer to a Datagrid
推荐答案
首先,我会移动填写到一个单独的功能:
First, I would move the Fill
to a separate function:
public void LoadData()
{
this.usersTableAdapter.Fill(this.workOrdersDataSet.users);
}
然后,当你做你的加载事件,你会调用该函数:
Then when you do your Load Event, you will call the function:
private void UserList_Load(object sender, EventArgs e)
{
LoadData();
}
如果您有对数据进行修改的另一种形式,你可以调用这个函数在另一个事件,与此类似。我使用的DialogResult
在我的代码:
If you have another form that performs changes on the data, you can call this function in another event, similar to this. I use DialogResult
in my code:
private void OpenOtherForm()
{
DialogResult openForm = new OtherForm().ShowDialog();
if(openForm == DialogResult.OK)
LoadData();
}
在你对其它形式后您的更新过程是完整的代码,包括行代码要告诉你的主要形式更新:
In your code for the other Form after your update process is complete, include a line of code to tell your main form to update:
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
那么,告诉你的主要形式,以触发数据的刷新,只有当一个更新实际发生。
using the DialogResult
then, tells your main form to trigger the Refresh of the Data only when an Update actually takes place.
这篇关于刷新使用TableAdapter的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!