来自数据库的Listview图像列表

时间:2019-03-09 08:06:07

标签: c# .net listview imagelist

我想从数据库中绑定一个图像列表,但我正在获取图像名称,但没有图像可以帮助我

https://my.pcloud.com/publink/show?code=XZVs9q7ZQeWB0GN02mFHjLflE9oq5btE83mX

上面的链接是我的输出,但我也想获取图像

public void ListimageGalery()        {

       ImageList myimagelistsmall = new ImageList();
       ImageList myimageListLarge = new ImageList();
       ImageList myimagelist = new ImageList();

       ListImage.SmallImageList = myimagelistsmall;
       ListImage.LargeImageList = myimageListLarge;

       myimagelist.ImageSize = new Size(50, 50);
       myimagelistsmall.ImageSize = new Size(32, 32);
       myimageListLarge.ImageSize = new Size(80, 80);
       try
       {
           con = new SqlConnection(connectionpath);
           SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("SELECT StockItemImage,STKDESCP FROM Tbl_STKMaster", con));
           DataSet dataSet = new DataSet();
           dataAdapter.Fill(dataSet);

           ListImage.Items.Clear();
           myimageListLarge.Images.Clear();
           myimagelistsmall.Images.Clear();
          foreach(DataRow dr in dataSet.Tables[0].Rows)
           {
               try
               {
                   Byte[] data = new Byte[0];
                   data = (Byte[])(dataSet.Tables[0].Rows[0]["StockItemImage"]);
                   MemoryStream mem = new MemoryStream(data);
                   myimagelist.Images.Add(Image.FromStream(mem));
                   myimagelistsmall.Images.Add(Image.FromStream(mem));
                   myimageListLarge.Images.Add(Image.FromStream(mem));


               }
               catch (Exception ex) { MessageBox.Show(ex.Message); }
               ListImage.LargeImageList = myimageListLarge;
               ListImage.Items.Add(dataSet.Tables[0].Rows[0]["STKDESCP"].ToString());
               ListImage.View = View.LargeIcon;
               //ListImage.SmallImageList = myimagelist;
               //ListImage.Items.Add(dataSet.Tables[0].Rows[0]["STKDESCP"].ToString());
           }

0 个答案:

没有答案