Listviewitem有多个子项? [英] Listviewitem with multiple subitems?
问题描述
你好
我正在制作一个webbrowser,但我想添加历史和下载
,他们的数据在列表框中
因此下载列表视图包含文件名作为listviewitem,日期和网址作为子项目,历史列表视图包含文档标题为listviewitem,url和日期为子项目
i尝试使用此代码管理它
hello
I''m making a webbrowser but i want to add history and downloads
and their data is in a listbox
so the listview for the downloads contains the filename as a listviewitem and the date and url as subitems and the history listview contains the document title as listviewitem and url and date as subitems
i tried to manage that with this code
If My.Settings.Downloads IsNot Nothing Then
For Each downloaditm As String In My.Settings.Downloads
If Not String.IsNullOrWhiteSpace(downloaditm) Then
Dim downloaditm_Array() As String = downloaditm.Split("|"c)
Dim listViewItem As New ListViewItem(downloaditm_Array(0))
listViewItem.SubItems.Add(downloaditm_Array(1))
listViewItem.SubItems.Add(downloaditm_Array(2))
ListView1.Items.Add(listViewItem)
End If
Next
Else
My.Settings.Downloads = New Specialized.StringCollection
End If
If My.Settings.History IsNot Nothing Then
For Each hisitm As String In My.Settings.History
If Not String.IsNullOrWhiteSpace(hisitm) Then
Dim hisitm_Array() As String = hisitm.Split("|"c)
Dim listViewItem As New ListViewItem(hisitm_Array(0))
listViewItem.SubItems.Add(hisitm_Array(1))
listViewItem.SubItems.Add(hisitm_Array(2))
ListView2.Items.Add(listViewItem)
End If
Next
Else
My.Settings.History = New Specialized.StringCollection
End If
我的表格的加载事件,但我给了我一个超出范围的索引
但是当我下载的东西或访问过链接时它工作正常
代码:
which is in the load event of my form but i gives me an index out of range exeption
but the one when i downloaded something or visited a link it works fine
code:
'History
Dim newItem As New ListViewItem(DirectCast(sender, WebKitBrowser).DocumentTitle)
newItem.SubItems.Add(DirectCast(sender, WebKitBrowser).Url.ToString)
newItem.SubItems.Add(DateAndTime.Now)
ListView2.Items.Add(newItem)
My.Settings.Downloads.Add(DirectCast(sender, WebKitBrowser).DocumentTitle + "|" + e.Url.ToString + "|" + DateAndTime.Now)
My.Settings.Save()
'Downloads
Dim newItem As New ListViewItem(e.SuggestedFileName)
newItem.SubItems.Add(e.Url.ToString)
newItem.SubItems.Add(DateAndTime.Now)
ListView1.Items.Add(newItem)
My.Settings.Downloads.Add(e.SuggestedFileName + "|" + e.Url.ToString + "|" + DateAndTime.Now)
My.Settings.Save()
所以你知道如何解决这个问题
so do you have any idea how i can fix this problem
推荐答案
我建议你将表单加载事件代码包装在如果不是Me.DesignMode
阻止它只会在你运行程序时执行。
建议更改
I suggest that you wrap the Form Load Event code in anIf Not Me.DesignMode
block so that it will only get executed when you are running the program.
Suggested Change
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Me.DesignMode then
... Form Load Event code goes here ...
End If
End Sub
这篇关于Listviewitem有多个子项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!