Private Sub dow30_1min()
        command("Dow 30", "http://www.investing.com/indices/us-30-futures-technical?period=60", "1 minutes")
    End Sub

    Public Sub command(ByRef name As String, ByRef webadd As String, ByRef time As String)
        WebBrowser1.Navigate(webadd)
        Dim a As String
        Dim b As String
        Dim c As String
        Dim d As String
        Dim f As String
        Dim newItem As ListViewItem
        a = InStr(TextBox1.Text, stb.Text)
        b = InStr(TextBox1.Text, by.Text)
        c = InStr(TextBox1.Text, sl.Text)
        d = InStr(TextBox1.Text, sts.Text)
        f = InStr(TextBox1.Text, nl.Text)
        If a Then
            newItem = ListView2.Items.Add(Format(Now, "Short Time") & " " & Format(Now, "Short Date")) 'col no. 1  
            With newItem
                .UseItemStyleForSubItems = False
                .SubItems.Add(Trim(name)) 'col no. 2 
                .SubItems.Add(Trim("STRONG BUY")) 'col no. 4  
                .SubItems.Add(Trim(time))
                .SubItems(2).BackColor = Color.Green
                .SubItems(2).ForeColor = Color.White
            End With

        ElseIf b Then
            newItem = ListView2.Items.Add(Format(Now, "Short Time") & " " & Format(Now, "Short Date")) 'col no. 1  
            With newItem
                .UseItemStyleForSubItems = False
                .SubItems.Add(Trim(name)) 'col no. 2 
                .SubItems.Add(Trim("BUY")) 'col no. 4  
                .SubItems.Add(Trim(time))
                .SubItems(2).BackColor = Color.Green
                .SubItems(2).ForeColor = Color.White
            End With

        ElseIf c Then
            newItem = ListView2.Items.Add(Format(Now, "Short Time") & " " & Format(Now, "Short Date")) 'col no. 1  
            With newItem
                .UseItemStyleForSubItems = False
                .SubItems.Add(Trim(name)) 'col no. 2 
                .SubItems.Add(Trim("SELL")) 'col no. 4  
                .SubItems.Add(Trim(time))
                .SubItems(2).BackColor = Color.Red
                .SubItems(2).ForeColor = Color.White
            End With

        ElseIf d Then
            newItem = ListView2.Items.Add(Format(Now, "Short Time") & " " & Format(Now, "Short Date")) 'col no. 1  
            With newItem
                .UseItemStyleForSubItems = False
                .SubItems.Add(Trim(name)) 'col no. 2 
                .SubItems.Add(Trim("STRONG SELL")) 'col no. 4  
                .SubItems.Add(Trim(time))
                .SubItems(2).BackColor = Color.Red
                .SubItems(2).ForeColor = Color.White
            End With

        ElseIf f Then
            newItem = ListView2.Items.Add(Format(Now, "Short Time") & " " & Format(Now, "Short Date")) 'col no. 1  
            With newItem
                .UseItemStyleForSubItems = False
                .SubItems.Add(Trim(name)) 'col no. 2 
                .SubItems.Add(Trim("NEUTRAL")) 'col no. 4 
                .SubItems.Add(Trim(time))
                .SubItems(2).BackColor = Color.Gray
                .SubItems(2).ForeColor = Color.White
            End With
        End If

        Dim myWriter As New IO.StreamWriter(Application.CommonAppDataPath & "\" & name & ".txt")
        For Each myItem As ListViewItem In ListView2.Items '// loop threw all items in ListView.
            With myItem
                '// write Item & "#" & SubItems... "#" is used for when loading each line and splitting it into arrays.
                myWriter.WriteLine(myItem.Text & "#" & .SubItems(1).Text & "#" & .SubItems(2).Text & "#" & .SubItems(3).Text & "#" & .SubItems(4).Text & "#" & .SubItems(5).Text & "#" & .SubItems(6).Text & "#" & .SubItems(7).Text & "#" & .SubItems(8).Text & "#" & .SubItems(9).Text)
            End With
        Next
        myWriter.Close()

    End Sub

if u can see the "1 minutes" at the "dow30_1min",I need to do 1 minutes, 5 ,15, 30 ,1hour ,5hours, 1day, 1month
but my listview is do like this:
http://i.imgur.com/qOTGq2U.png?1

before this is like this:
Click Here

if do like the new one, this code cannot working fine right?
now i very confusing.....pls tell me this code can working or not....while u all answering this question, I will try myself

Dani AI

Generated

Short answer: yes — you can add subitems at any time (right after you Add the ListViewItem or later), but you must manage column indexes and how you save the rows. , your code creates items with a few subitems but then your save loop assumes nine subitems exist; that will throw an index error when some rows have fewer subitems. is right that the question needs a bit of framing — the practical fixes are below.

Remember how indexes work: ListViewItem.Text is the first column (same as SubItems(0)). Each call to item.SubItems.Add(...) creates the next column (SubItems(1), SubItems(2), ...). You can keep the ListViewItem reference and call item.SubItems.Add(...) later from anywhere. Example pattern (concise):

' create and add
Dim li As New ListViewItem(DateTime.Now.ToString("g"))
ListView2.Items.Add(li)

' later: append columns for that row
li.SubItems.Add("Instrument")
li.SubItems.Add("BUY")
li.SubItems.Add("1m")

Make the save routine robust: don't assume a fixed number of subitems. Build the output by filling missing columns with empty strings so you never index past the end:

Dim colsExpected As Integer = 10
Dim parts As New List(Of String)
parts.Add(myItem.Text)
For i As Integer = 1 To colsExpected - 1
  parts.Add(If(myItem.SubItems.Count > i, myItem.SubItems(i).Text, String.Empty))
Next
myWriter.WriteLine(String.Join("#", parts))

Extra tips: use String.IndexOf(..., StringComparison.OrdinalIgnoreCase) >= 0 (or String.Contains) instead of InStr and test explicitly (> 0) to avoid surprises; enable Option Strict On; set the ListView View = Details and create the Columns in the designer to match how many subitems you expect; use UseItemStyleForSubItems = False to color individual subitems (as you already try). If you need multiple timeframes per symbol in a tidy grid, consider a DataGridView or store per-symbol data in the item Tag and render rows from that model instead of forcing many variable subitems.

You are confusing me with headline of yourThread and what you wrote underneath. What is you question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.