views:

271

answers:

0

I have a listview and an imagelist that I populate with thumbnails dynamically through the backgroundWorker function. Once that is finished, I have it overwrite the imageList and listView in the main form's view, and if I watch the debugger watch list, it updates perfectly(this creates thumbnails and links them via tags to the appropriate page number in a multi-page tiff file), so I know that the data is there, but the listview itself never refreshes to show the new data in it.

I've tried:

refresh()

update()

hide()/show()

visible false/true

invalidate()

beginupdate()/endupdate()/refresh()

    Private Sub frmTiffImage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                Dim imgInfo As New FileInfo(ImagePath)
                If LCase(imgInfo.Extension) = ".tif" Or LCase(imgInfo.Extension) = ".tiff" Then
                    BuildZoomLevels()
                    tiffImage = FreeImageAPI.FreeImage.OpenMultiBitmapEx(ImagePath)
                    pageCount = FreeImage.GetPageCount(tiffImage)
                    ReDim rotation(pageCount - 1)
                    ChangePage(0)
                    EnableNavButtons(False, False, False, False)
                    Me.bckGndWkr.RunWorkerAsync()
                ElseIf imgInfo.Extension = ".pdf" Then
                    MsgBox("PDF Support is not enabled yet.")
                End If
            Catch ex As Exception
                RaiseError(ex)
            End Try
        End Sub

    Private Sub bckGndWkr_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bckGndWkr.DoWork
        Dim bw As BackgroundWorker = CType(sender, BackgroundWorker)

        e.Result = createThumbnails(bw, tiffImage, pageCount)

    End Sub

Private Function createThumbnails(ByVal bw As BackgroundWorker, ByVal multiImage As FreeImageAPI.FIMULTIBITMAP, ByVal pageTotal As Integer) As returnData
        Dim rtn As New returnData
        Dim imgThumbnails As ImageList
        Dim lstThumbnails As DevComponents.DotNetBar.Controls.ListViewEx
        imgThumbnails = New ImageList
        lstThumbnails = New DevComponents.DotNetBar.Controls.ListViewEx
        imgThumbnails.ImageSize = New Size(100, 100)
        lstThumbnails.LargeImageList = imgThumbnails
        lstThumbnails.SmallImageList = imgThumbnails
        Dim page As Integer
        For page = 0 To (pageTotal - 1)
            Dim imagePage As FreeImageAPI.FIBITMAP
            imagePage = FreeImage.LockPage(multiImage, page)
            imgThumbnails = ThumbCreate(imagePage, page, imgThumbnails)
            FreeImage.UnlockPage(multiImage, imagePage, False)
            Dim prepend As String = ""
            Dim count As Integer
            For Each count In New Integer() {10, 100, 1000}
                If (pageCount >= count) Then
                    If ((page + 1) <= (count - 1)) Then
                        prepend += "0"
                    Else
                        Continue For
                    End If
                Else
                    Continue For
                End If
            Next
            Dim item As New ListViewItem(prepend & CStr(page + 1), page)
            lstThumbnails.Items.Add(item)
            Dim percentComplete As Integer = CInt(((page + 1) / pageCount) * 100)
            bw.ReportProgress(percentComplete)
        Next
        rtn.imgThumbList = imgThumbnails
        rtn.lstThumbList = lstThumbnails
        Return rtn
    End Function

 Private Sub bckGndWkr_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bckGndWkr.ProgressChanged
        progThumbLoad.Value = e.ProgressPercentage()
    End Sub

    Private Sub bckGndWkr_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bckGndWkr.RunWorkerCompleted
        Dim rtn As New returnData
        If (e.Error IsNot Nothing) Then
            RaiseError(e.Error.GetBaseException)
        Else
            rtn = e.Result
            imgThumbsList = rtn.imgThumbList
            lstThumbs = rtn.lstThumbList
            progThumbLoad.Visible = False
            EnableNavButtons(False, False, True, True)
            enableRotButtons(True, True)
            enableZoomButtons(True, True, True)
            btnPrint.Enabled = True
            txtboxPage.Enabled = False
        End If
    End Sub

any ideas as to how to make this work?