0
Private Sub RETRIEVE()
    ListView1.Clear()
    Dim imglist As New ImageList
    imglist.ColorDepth = ColorDepth.Depth32Bit
    ListView1.LargeImageList = imglist
    ListView1.LargeImageList.ImageSize = New System.Drawing.Size(50, 50)

    Dim connection As New SqlConnection("Data Source=(local);Initial Catalog=images;Integrated Security=True")
    Dim userdataadpter As New SqlDataAdapter("SELECT * FROM tbl_img ", connection)
    Dim userdataset As New DataSet
    Dim dt_images As New DataTable
    userdataadpter.Fill(userdataset, "tbl_img")

    For Each dr As DataRow In dt_images.Rows
        Dim img_buffer = CType(dr("image"), Byte())
        Dim img_stream As New MemoryStream(img_buffer, True)
        img_stream.Write(img_buffer, 0, img_stream.Length)
        imglist.Images.Add(dr("image").ToString(), New Bitmap(img_stream))
        img_stream.Close()
        Dim lsvpaarent As New ListViewItem
        lsvpaarent.Text = dr("image").ToString
        lsvpaarent.ImageKey = dr("imageID").ToString
        ListView1.Items.Add(lsvpaarent)
    Next
end sub
4

1 回答 1

0

看起来您将图像保存为数据库中的字节数组并将它们拉出,将它们放入图像列表中,创建列表视图项,然后将“ImageKey”分配给图像列表的“ImageId”?

ImageKey 应该引用图像列表中项目的索引,而不是数据库中的某个 id。

看看这是否适合你。

于 2013-09-20T22:55:32.303 回答