Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET WinForm
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
Posted 20-Feb-13 6:54am
Edited 20-Feb-13 8:47am
Mike Meinz23.2K
v3
Comments
Richard MacCutchan at 20-Feb-13 13:29pm
   
You need to use your debugger to step through the code and check why the index is not valid.
Bart de Lange at 20-Feb-13 13:38pm
   
this line
listViewItem.SubItems.Add(hisitm_Array(2))
but if i replace it with this
listViewItem.SubItems.Add("hello CodeProject")
it works just fine
Mike Meinz at 20-Feb-13 13:40pm
   
Please use the Visual Studio Debugger to step through the code and let us know the line of code that gets the error and the values of the pertinent variables.
 
My guess is that either downloaditm or hisitm does not contain three tokens to be split into the associated array. Your code does not check the length of the associated array after the Split.
Bart de Lange at 20-Feb-13 13:49pm
   
ive added an example string which is: Google|www.google.com|20-2-2013 19:30:40
so it does contain the right characters

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I suggest that you wrap the Form Load Event code in an If 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
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100