Click here to Skip to main content
15,894,343 members

Listviewitem with multiple subitems?

Bart de Lange asked:

Open original thread
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

VB
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:
VB
'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
Tags: Visual Basic, Windows Forms

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900