listview item zweite zeile auslesen

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von Petergolf.

    listview item zweite zeile auslesen

    Hey leute ich versuche listview items zu speichern das klappt mit dem code auch :

    VB.NET-Quellcode

    1. System.IO.File.WriteAllText(Application.StartupPath & "\admin\Loader.dspl", ListView1.Items(0).Text + "," + ListView1.Items(0).SubItems(1).Text + "," + ListView1.Items(0).SubItems(2).Text + vbCrLf)


    aber der speichert nur eine zeile wie bekomm ich hin das der die anderen auch noch speichert ?

    bitte helft mir ich bin am verzweifeln
    :whistling:

    VB.NET-Quellcode

    1. Using Writer As New System.IO.BinaryWriter(System.IO.File.Open(Dein Pfad, System.IO.FileMode.Create, System.IO.FileAccess.Write))
    2. For Each Item As ListViewItem In ListView1.Items
    3. For Each Subitem As ListViewItem.ListViewSubItem In Item.SubItems
    4. Writer.Write(Item.Text + Subitem.Text)
    5. Next

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „programmer71“ ()

    VB.NET-Quellcode

    1. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    2. Dim myWriter As New IO.StreamWriter("C:\Users\zeus\Desktop\Neuer Ordner (4)\Save.cfg")
    3. For Each myItem As ListViewItem In ListView1.Items
    4. myWriter.WriteLine(myItem.Text & myItem.SubItems(0).Text) '// write Item and SubItem.
    5. Next
    6. myWriter.Close()
    7. End Sub


    LG ^^
    Ich hab was aus etlichen stücken zusammen gebaut ^^

    Aber das geht Top :!: (Teil von Dieter Otter)

    IN TXT SPEICHERN

    VB.NET-Quellcode

    1. Dim ListViewContent As String = ""
    2. Dim Path As String = "C:\Users\zeus\Desktop\Neuer Ordner (4)\Save.cfg"




    VB.NET-Quellcode

    1. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    2. For I As Integer = 0 To ListView1.Items.Count - 1
    3. For Int As Integer = 0 To ListView1.Items.Item(I).SubItems().Count - 1
    4. ListViewContent += ListView1.Items.Item(I).SubItems(Int).Text & " "
    5. Next
    6. ListViewContent += vbNewLine
    7. Next
    8. If System.IO.File.Exists(Path) Then
    9. System.IO.File.Delete(Path)
    10. End If
    11. System.IO.File.AppendAllText(Path, ListViewContent)
    12. End Sub
    13. End Class




    AUS TXT LADEN: (Teil des Cods von Dieter Otter)

    VB.NET-Quellcode

    1. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    2. Dim sLine As String
    3. Dim sItem() As String
    4. Dim ItemX As ListViewItem
    5. Dim IntCols As Integer
    6. IntCols = ListView1.Columns.Count
    7. FileOpen(1, Path, OpenMode.Input)
    8. With ListView1.Items
    9. While Not EOF(1)
    10. sLine = LineInput(1)
    11. sItem = Split(sLine, " ")
    12. ItemX = .Add(sItem(0), sItem(1))
    13. For I = 2 To IntCols
    14. ItemX.SubItems.Add(sItem(I))
    15. Next I
    16. End While
    17. End With
    18. FileClose(1)
    19. End Sub



    EDIT:

    ListViewer sind schrecklich kompliziert 8|

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „TVX“ ()

    Lösung:

    Dim s As String = ""
    For Each i As Object In ListBox1.Items
    s &= i.Text + "," & i.SubItems(1).Text & "," & i.SubItems(2).Text & vbNewLine
    Next
    IO.File.WriteAllText(Application.StartupPath & "\admin\Loader.dspl", s)


    Beispiel in meinem Fall :)

    Danke noch mal an alle :thumbsup: