日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

datagrid wpf 刷新数据_c# – WPF Datagrid-自动刷新

發布時間:2024/9/18 C# 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 datagrid wpf 刷新数据_c# – WPF Datagrid-自动刷新 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有很多方法可以改善你的上述內容.但這是我會為初學者嘗試的.

下面將在頁面加載時填充您的數據網格,將計時器設置為每60秒打勾一次.當計時器滴答時,它將調用一種方法將數據再次加載到網格中.

//On PageLoad,populate the grid,and set a timer to repeat ever 60 seconds

private void Page_Loaded(object sender,RoutedEventArgs e)

{

try

{

RebindData();

SetTimer();

}

catch (SqlException e)

{

Console.WriteLine(e.Message);

}

}

//Refreshes grid data on timer tick

protected void dispatcherTimer_Tick(object sender,EventArgs e)

{

RebindData();

}

//Get data and bind to the grid

private void RebindData()

{

String selectstatement = "select top 2 ItemID,DOJ from ConsumarTB order by ItemID ";

da = new SqlDataAdapter(selectstatement,con);

ds = new DataSet();

da.Fill(ds);

dataGrid1.ItemsSource = ds.Tables[0].DefaultView;

}

//Set and start the timer

private void SetTimer()

{

DispatcherTimer dispatcherTimer = new DispatcherTimer();

dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);

dispatcherTimer.Interval = new TimeSpan(0,60);

dispatcherTimer.Start();

}

總結

以上是生活随笔為你收集整理的datagrid wpf 刷新数据_c# – WPF Datagrid-自动刷新的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。