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

歡迎訪問 生活随笔!

生活随笔

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

C#

C#旅程——ListView控件使用

發布時間:2023/12/10 C# 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#旅程——ListView控件使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、 添加表頭

this.listView1.Columns.Add("ID", 200, HorizontalAlignment.Center); //列名,長度,顯示方式 this.listView1.Columns.Add("R/S", 200, HorizontalAlignment.Center); //一步添加 this.listView1.Columns.Add("Data Len", 200, HorizontalAlignment.Center); //一步添加 this.listView1.Columns.Add("Data", 300, HorizontalAlignment.Center); //一步添加

可以載添加控件后在屬性中添加表頭

2、添加每行的內容

ListViewItem lvi = new ListViewItem(); lvi.Text = ID; lvi.SubItems.Add(RS); lvi.SubItems.Add(DataLen.ToString()); lvi.SubItems.Add(DataBuffer);this.listView1.Items.Add(lvi);

效果圖:
3、當數據更新速度太快,導致界面閃爍,解決方法如下:
首先建立一個類繼承自System.Windows.Forms.ListView
代碼:

class ListViewNF : System.Windows.Forms.ListView{public ListViewNF(){// 開啟雙緩沖this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);// Enable the OnNotifyMessage event so we get a chance to filter out // Windows messages before they get to the form's WndProcthis.SetStyle(ControlStyles.EnableNotifyMessage, true);}protected override void OnNotifyMessage(Message m){//Filter out the WM_ERASEBKGND messageif (m.Msg != 0x14){base.OnNotifyMessage(m);}}

然后修改對應Designer文件中的以下代碼:

System.Windows.Forms.ListView listView1;

修改為

ListViewNF listView1;

listView1 = System.Windows.Forms.ListView();

修改為

listView1 = new ListViewNF();

針對于大量刷新數據,datagridview會有緩沖延遲,而ListView可以短時間內處理大量的數據,將閃爍問題解決后,顯示數據不會出現延時問題。

總結

以上是生活随笔為你收集整理的C#旅程——ListView控件使用的全部內容,希望文章能夠幫你解決所遇到的問題。

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