English 中文(简体)
如何更新数据 观点实时执行?
原标题:How to update DataGridView real time execution?

My DataGridView displays information that is entered on another system. As the user insert, update or delete any information, the DataGridView should be updated right now.
I thought about using a recursive method or thread background, but it did not help.
My code is:

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();
    }

}

这不能奏效,谁能帮助我?

问题回答

这样做的最简单方式(如Sshahid Iqbal所说)是在规定的时间间隔内使用一个时间,并将你的数据网格对数据来源进行重新设计,但用户可能不会改变相关的数据来源。

但是,如果你想采取更强有力的办法,则采取下列行动:

实时 DataGridView?

你们看到,履行这一职能需要一些时间。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签