我想在数据网格上显示消息,例如'检索数据'在填充数据表的同时。有没有机会实现它?
这是填充数据表的代码;
public void getAlertGrid()
{
odaAlert = new OracleDataAdapter(getAlert, oradb); //odaAlert is Adapter
odaAlert.Fill(dtAlert); // dtAlert is Datatable
ugAlert.DataSource = dtAlert;
}
答案 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());