如何刷新listview中的图像列表图像

如何刷新listview中的图像列表图像

本文介绍了如何刷新listview中的图像列表图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在listview控件中显示图像和一些数据,我遇到了在每一行显示相同图像的问题。

图像路径是网站url。

任何人都可以修改我的源代码

提前谢谢



Hi,
I am displaying images and some datas in listview control and I have faced a problem showing same images on every single row.
The image paths are website url.
Can anybody fix my source code
Thank you in advance

private void Form1_Load(object sender, EventArgs e)
       {
           show_all_items();
       }

       public void show_all_items()
       {

           lv_main.Items.Clear();

           using (SQLiteConnection conn = new SQLiteConnection(strConn))
           {
               conn.Open();

               string str_select = "SELECT * FROM cars limit 30";

               using (SQLiteCommand cmd = new SQLiteCommand(str_select, conn))
               {
                   using (SQLiteDataReader rdr = cmd.ExecuteReader())
                   {
                       while (rdr.Read())
                       {
                           ListViewItem item = new ListViewItem();

                           ImageList imgList = new ImageList();

                           imgList.Images.Add(LoadImage(rdr["thumnail_url"].ToString()));
                           imgList.ImageSize = new Size(55, 40);

                           lv_main.SmallImageList = imgList;

                           item.ImageIndex = 0;


                           item.SubItems.Add(rdr["carName"].ToString());
                           item.SubItems.Add(rdr["mission"].ToString());
                           item.SubItems.Add(rdr["born"].ToString());
                           item.SubItems.Add(rdr["gas"].ToString());
                           item.SubItems.Add(rdr["mile"].ToString());
                           item.SubItems.Add(rdr["price"].ToString());
                           item.SubItems.Add(rdr["color"].ToString());



                           DateTime regDate = (DateTime)rdr["regDate"];
                           item.SubItems.Add(regDate.ToShortDateString());

                           lv_main.Items.Add(item);


                        }
                       rdr.Close();
                   }
               }

               conn.Close();
           }



       }
       private Image LoadImage(string url)
       {
           System.Net.WebRequest request =
               System.Net.WebRequest.Create(url);

           System.Net.WebResponse response = request.GetResponse();
           System.IO.Stream responseStream =
               response.GetResponseStream();

           Bitmap bmp = new Bitmap(responseStream);

           responseStream.Dispose();

           return bmp;
       }

   }





我尝试过:



我使用了imagelist.dispose(),listview.refresh(),listview.dispose()等...



What I have tried:

I used imagelist.dispose() ,listview.refresh(),listview.dispose() etc...

推荐答案


这篇关于如何刷新listview中的图像列表图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:23