1

我尝试将图像从 ImageList 加载到 ListView 并且效果很好......但是当加载表单时,ImageList 的最后一个图像没有出现......我将在组合框 selectedIndexChanged 事件和表单中调用此过程加载...当表单加载时,ImageList 中的最后一个图像没有出现,当我多次单击组合框时,所有图像都按预期显示...有什么帮助吗?这是代码..

Private Sub LoadMenuItem()

    lvItem.Clear()
    Dim adptItem As New Restaurant_Management_SystemDataSetTableAdapters.ItemTableAdapter
    Dim categoryID As Integer = cboccategory.SelectedValue
    Dim dtItem As Restaurant_Management_SystemDataSet.ItemDataTable = adptItem.GetDataByCategoryID(categoryID)

    lvItem.BeginUpdate()
    For Each drItem As Restaurant_Management_SystemDataSet.ItemRow In dtItem.Rows
        Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(drItem.ImageForItem)
        Dim img As Image = System.Drawing.Image.FromStream(ms)
        ImageList1.Images.Add(drItem.ItemID, img)
        lvItem.Items.Add(drItem.ItemName.Trim, drItem.ItemID)
    Next
    lvItem.EndUpdate()

    cboItem.ValueMember = "ItemID"
    cboItem.DisplayMember = "ItemName"
    cboItem.DataSource = dtItem
    lvItem.Refresh
End Sub
4

0 回答 0