在VB.Net中的Listview中更改下载百分比

问题描述

我正在使用webclient的DownloadProgressChanged事件在列表视图中显示下载文件的下载百分比。

当我在标签显示“ Overallpercent”时,代码工作得很好,但是它给了我“ System.NullReferenceException:'对象引用未设置为对象的实例。'在列表视图中。

我用于更改listview子项的代码如下

Private Sub downloadprogressruntimemade(currentimage As Integer,totalimages As Integer,li As ListViewItem,indexnumberforlv As Integer,ByVal sender As Object,ByVal e As DownloadProgressChangedEventArgs)

        Dim li1 As ListViewItem = li
        Dim overallpercent = Math.Round((currentimage / totalimages) * 100,2) + Math.Round(e.Progresspercentage / 1 / totalimages,2)
        li1.SubItems.Insert(indexnumberforlv,New ListViewItem.ListViewSubItem(nothing,overallpercent & " %"))
        refreshcontrol(LVsessionnotfound)
               
End Sub

我@R_404_6329@想念什么?

解决方法

我想我发现了这个错误,这要感谢@Hans Passant提到插入将是错误的方法。.我将插入更改为int main() { char *buffer; char c = *buffer; // undefined behavior: reading from an uninitialized pointer *buffer = '\0'; // undefined behavior: writing through an uninitialized pointer printf("%p\n",(void *)buffer); // undefined behavior: reading an uninitialized variable } ,效果很好。