none
need help with a text file RRS feed

  • Question

  •     I need to load this into a listview but not sure how to do it . this dose have

    SetDelimiters(vbTab) in it. and the code block is only giving me one line of text not both lines like I need

     If System.IO.File.Exists("C:\Sales\" & order2 & ".txt") Then
                Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Sales\" & order2 & ".txt")
                    MyReader.TextFieldType = FileIO.FieldType.Delimited
                    MyReader.SetDelimiters(vbTab)
                    Dim CurrentRow As String()
                    While Not MyReader.EndOfData
                        CurrentRow = MyReader.ReadFields
                        Dim NewItem As New ListViewItem(CurrentRow(0))
                        For x As Integer = 1 To CurrentRow.GetUpperBound(0)
                            NewItem.SubItems.Add(CurrentRow(x))
    
    
                        Next
    
    
                        ListView2.Items.Add(NewItem)
                    End While
                End Using
            End If

    Tuesday, February 26, 2019 3:09 AM

All replies

  • Hi,

    add code:

    ListView2.View = View.List

    my code:

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListView2.View = View.List
            Dim order2 As String = "test"
            If System.IO.File.Exists("D:\Sales\" & order2 & ".txt") Then
                Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("D:\Sales\" & order2 & ".txt")
                    MyReader.TextFieldType = FileIO.FieldType.Delimited
                    MyReader.SetDelimiters(vbTab)
                    Dim CurrentRow As String()
                    While Not MyReader.EndOfData
                        CurrentRow = MyReader.ReadFields
                        Dim NewItem As New ListViewItem(CurrentRow(0))
                        For x As Integer = 1 To CurrentRow.GetUpperBound(0)
                            NewItem.SubItems.Add(CurrentRow(x))
                        Next
                        ListView2.Items.Add(NewItem)
                    End While
                End Using
            End If
        End Sub
    End Class
    

    Best Regards,

    Alex



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 26, 2019 5:25 AM
  • sorry Alex but must be in listview2.view =   view.details  
    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
            On Error Resume Next
            If ListView1.SelectedItems(0).SubItems(0).Text() = "" Then
                Exit Sub
            End If
            Dim order2 As String
    
            order2 = ListView1.SelectedItems(0).SubItems(0).Text()
    
            TextBox1.Text = order2
    
    
            If System.IO.File.Exists("C:\Sales\" & order2 & ".txt") Then
                Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Sales\" & order2 & ".txt")
                    MyReader.TextFieldType = FileIO.FieldType.Delimited
                    MyReader.SetDelimiters(vbTab)
                    Dim CurrentRow As String()
                    While Not MyReader.EndOfData
                        CurrentRow = MyReader.ReadFields
                        Dim NewItem As New ListViewItem(CurrentRow(0))
                        For x As Integer = 1 To CurrentRow.GetUpperBound(0)
                            NewItem.SubItems.Add(CurrentRow(x))
    
    
                        Next
    
    
                        ListView2.Items.Add(NewItem)
                    End While
                End Using
            End If
    
        End Sub

    mode  
    Tuesday, February 26, 2019 1:23 PM
  • Hi,

    Is this Okey?

    Public Class Form1
        Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
            On Error Resume Next
            If ListView1.SelectedItems(0).SubItems(0).Text() = "" Then
                Exit Sub
            End If
            Dim order2 As String
    
            order2 = ListView1.SelectedItems(0).SubItems(0).Text()
    
            TextBox1.Text = order2
    
    
            If System.IO.File.Exists("D:\Sales\" & order2 & ".txt") Then
                Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("D:\Sales\" & order2 & ".txt")
                    MyReader.TextFieldType = FileIO.FieldType.Delimited
                    MyReader.SetDelimiters(vbTab)
                    Dim CurrentRow As String()
                    While Not MyReader.EndOfData
                        CurrentRow = MyReader.ReadFields
                        Dim NewItem As New ListViewItem(CurrentRow(0))
                        For x As Integer = 1 To CurrentRow.GetUpperBound(0)
                            NewItem.SubItems.Add(CurrentRow(x))
    
    
                        Next
    
    
                        ListView2.Items.Add(NewItem)
                    End While
                End Using
            End If
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListView2.View = View.Details
    
            ListView2.Columns.Add("Column1", 500, HorizontalAlignment.Left)
    
            ListView1.Items.Add(New ListViewItem(New String() {"test"}))
    
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 27, 2019 8:37 AM
  • it works but it gives me a 0  in my Customer Order#   if I could git rid of that I could deal with that, the line you given me

    ListView1.Items.Add(

    NewListViewItem(NewString() {OrderNumber1}))

    is what is giving me the 0   
    Wednesday, February 27, 2019 10:03 AM
  • Hi,

    What do you mean by the following code to add 0 to the listview?OrderNumber1 is "0"?

    ListView1.Items.Add(NewListViewItem(NewString() {OrderNumber1}))

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 28, 2019 2:24 AM
  • no  what is happaning is that code is putting a 0  in the listview1
    Thursday, February 28, 2019 3:07 AM
  • Hi,

    Please provide your code so we can assist you, without code it is purely guess work.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 28, 2019 5:29 AM
  • ListView1.Items.Add(NewListViewItem(NewString() {OrderNumber1}))

    if you look above at the 2 forms that I provided it will show a 0 in listview1 customer order#, that 0 should not be there, repeat should not be there. the code above is giving me what I need but also the 0 that I don't need. 
    Thursday, February 28, 2019 1:15 PM
  • Hi,

    I want to know how the data of ListView1 is filled, give me the code.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 4, 2019 8:01 AM