簡體   English   中英

插入后刷新C#DataGridView

[英]C# DataGridView refresh after insert

我有一個表格A,上面是DataGridView和一個Button。 單擊按鈕后,將打開新表格B表格。

在表格B上,我有兩個文本框和“更新”按鈕。 單擊該按鈕后,數據將插入數據庫中。 並且表格B是關閉的。

如何更新DataGridView以獲取新數據。 從表格B無法訪問。

ShowDialog窗體B並在InsertButton單擊后返回DialogResult,從b調用后檢查,如果DialogResult為Yes,則重新綁定DataGridView(RefreshBindings)

//in Form A
private void btnOpenFromB_Click(sender,event)
{
FormB B =new FormB();
if(B.ShowDialog()==DilogResult.Yes)
   //Call RefreshMethod of DG
}


//In Form B
 //in Constructor
public FromB()
{
   initilizeComponents();
   DialogResult=DialogResult.No;
}
//In Insert Button Click
private void InserClick(sender,event)
{
    if(Checking()==true)
     { 
        //Insert Operations
        DialogResult=DilogResult.Yes;
        this.Close();
      }
}

嗨,在窗體B的構造函數中提供窗體A或在創建后添加窗體A,需要在關閉窗體之前更新網格。

第二種方式將數據放在Form A的字段中,然后在關閉更新網格之后等待Form B關閉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM