2017-02-03 46 views
1

我想在填寫數據表時在數據網格上顯示消息,如「正在檢索數據」。有沒有機會讓它發生?填寫數據表時顯示'正在檢索數據'消息

這是我填充數據表的代碼;

public void getAlertGrid() 

    { 
      odaAlert = new OracleDataAdapter(getAlert, oradb); //odaAlert is Adapter 
      odaAlert.Fill(dtAlert); // dtAlert is Datatable 
      ugAlert.DataSource = dtAlert; 
    } 
+0

使用'Backgroundworker'或'Thread' –

+0

@IkramTurgunbaev嗨。關於任務呢? –

+0

是的,你也可以使用任務 –

回答

0

由於@IkramTurgunbaev說你需要異步加載數據並更新狀態欄。在你打電話給你getAlertGrid方法的地方做這樣的事情:

private void MethodThatCallsGetAlertGrid() 
{ 
    // Show the progress bar and set the style of progress bar to Marquee. This will show continiously scrolling block across progress bar, as you cannot know the current progress percent 
    this.progressBar1.Visible = true; 
    this.progressBar1.Style = ProgressBarStyle.Marquee; 

    // Start loading the data source async 
    Task.Factory.StartNew(() => 
     this.getAlertGrid()) 
    .ContinueWith((antecedent) => 
    { 
     // Set data source on UI thread. Remove the same row from your getAlertGrid method 
     ugAlert.DataSource = dtAlert; 

     // Hide the progress bar 
     this.progressBar1.Visible = false; 
    }, TaskScheduler.FromCurrentSynchronizationContext()); 
相關問題