为什么Picture Box没有更新?

时间:2015-08-20 21:26:27

标签: vb.net

我有一个列表框,当所选索引发生更改时,它会解析该索引中的文本以获取密钥,对于字典,它会使用此键显示该索引的相关图像。至少它应该是。

当我第一次向列表框添加新项目时,updatePics子程序有效,但在更改索引时调用它时则不行。

parseLstBoxItem函数有效,我使用了消息框来验证这一点。

相关的键和列表存在于jobsDict词典中,使用autos进行验证。

我甚至尝试过使用断点,但我无法弄清楚出了什么问题。所以任何帮助都会非常感激!

相关的子/功能如下:

更改所选收件箱时更新所有内容:

    Private Sub lstbxJobs_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstbxJobs.SelectedIndexChanged
    currentJob = parseLstBxItem(lstbxJobs.SelectedIndex)
    MsgBox(parseLstBxItem(lstbxJobs.SelectedIndex))
    updatePics()
    updateTicks(JobsDict(currentJob).stage)
    populateList()
End Sub

更新下面的图片框和数字代码:

Public Sub updatePics()
    udImage.Maximum = JobsDict(currentJob).images.Count
    udImage.Minimum = 1
    udImage.Value = 1
    pctJobPics.ImageLocation = JobsDict(currentJob).images(0)
End Sub

字典定义为:

 Property JobsDict As New Dictionary(Of String, job)

它填充在这个子程序中(来自不同的形式):

 Public Sub initJob(ID As String, notes As String, product As String, eta As Integer)
    Orders.JobsDict.Add(ID, New job)
    Orders.JobsDict(ID).ID = ID
    Orders.JobsDict(ID).notes = notes
    Orders.JobsDict(ID).product = product
    Orders.JobsDict(ID).stage = 0
    Orders.JobsDict(ID).images = imgList
    Orders.JobsDict(ID).ETA = eta
    Orders.JobsDict(ID).bumped = False
    Orders.chkItemStage.SetItemChecked(0, True)

End Sub

job是一个自定义类,定义为:

Public Class job
Property ID As String
Property product As String
Property ETA As Integer
Property stage As Integer
Property notes As String
Property images As New List(Of String)
Property bumped As Boolean

Public Sub nextStage()
    If stage < 4 Then
        stage += 1
        Orders.updateTicks(stage)
    Else
        MsgBox("Job is already finished")
    End If
End Sub

结束班

imgList通过一个拖拽填充:

 Public Sub pctadd_drop(sender As Object, e As DragEventArgs) Handles pctAdd.DragDrop
    Dim picStr() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
    Dim newList As List(Of String) = picStr.ToList
    For Each img In newList
        If Not imgList.Contains(img) Then
            imgList.Add(img)
        Else
            MsgBox("Image already present")
        End If
    Next
    pctAdd.ImageLocation = imgList(newList.Count - 1)
    udPics.Maximum = newList.Count
    udPics.Value = newList.Count
    udPics.Minimum = 1
    txtID.Text = Strings.Right(imgList(0).Remove(imgList(0).Length - 4, 4), 4)
End Sub 

如果我遗漏了任何内容,请告诉我,我已尝试自行调试,但我真的无法看到问题出在哪里!

2 个答案:

答案 0 :(得分:1)

您将imgList分配给作业的图像属性在initJob中的方式是错误的。相同的imgList将用于所有作业。

将其更改为:

Public Sub initJob(ID As String, notes As String, product As String, eta As Integer)

    Orders.JobsDict.Add(ID, New job)
    Orders.JobsDict(ID).ID = ID
    Orders.JobsDict(ID).notes = notes
    Orders.JobsDict(ID).product = product
    Orders.JobsDict(ID).stage = 0
    Orders.JobsDict(ID).images = New List(of String)

    For Each strImage in imgList

        Orders.JobsDict(ID).images.Add(strImage)

    Next

    Orders.JobsDict(ID).ETA = eta
    Orders.JobsDict(ID).bumped = False
    Orders.chkItemStage.SetItemChecked(0, True)

End Sub

编辑:

为了澄清更多,当您将图像属性分配给传入的列表时,您实际上将其分配给imgList。最终,你有许多工作都共享同一个变量。通过将图像属性分配给它自己唯一的List(String)实例并从imgList复制值,图像对于每个Job都是唯一的(假设imgList的值已更改)。

答案 1 :(得分:0)

可爱的方法PictubeBox.Update会帮助你。

Public Sub updatePics()
     udImage.Maximum = JobsDict(currentJob).images.Count
     udImage.Minimum = 1
     udImage.Value = 1
     pctJobPics.ImageLocation = JobsDict(currentJob).images(0)
     pctJobPics.Image = JobsDict(currentJob).images(0) 'if don't works, disable this
     Call pctJobPics.Update()
End Sub