我的DataGridView
显示在另一个系统上输入的信息。当用户插入、更新或删除任何信息时,DataGridView
应该立即更新。
我想过使用递归方法或线程背景,但没有帮助。
我的代码是:
private void Andon_Load(object sender, EventArgs e)
{
LoadGrid();
}
private void LoadGrid()
{
DataTableWorkCall cdtwc = new DataTableWorkCall();
DataTable dtPBList = new DataTable();
dtPBList = cdtwc.CreatePendingWorkCall();
DataTableWorkCall.GetDataTableNew = dtPBList;
if (DataTableWorkCall.GetDataTableNew != DataTableWorkCall.GetDataTableOld)
{
if (DataTableWorkCall.GetDataTableNew.Rows.Count > 0)
{
DataTableWorkCall.GetDataTableOld = DataTableWorkCall.GetDataTableNew;
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
DataView dv = new DataView(DataTableWorkCall.GetDataTableNew);
dv.Sort = "workCallOpenDate DESC";
dgvAndon.DataSource = dv;
lblRefreshDate.Text = "Atualizado em: " + DateTime.Now;
existData = true;
}
else
{
if (this.WindowState == FormWindowState.Normal)
this.WindowState = FormWindowState.Minimized;
music.Clear();
music.StopSound();
lblRefreshDate.Text = "Atualizado em: " + DateTime.Now;
existData = false;
}
this.Activate();
//LoadGrid();
}
else
{
if (this.WindowState == FormWindowState.Normal)
this.WindowState = FormWindowState.Minimized;
lblRefreshDate.Text = "Atualizado em: " + DateTime.Now;
existData = false;
LoadGrid();
}
}
这不起作用,任何人都可以帮助我吗?