I need to enumerate the CSV headers and search for a header name and save it's column number to the currentRow like this I can add it to a listView. I have a code example and commented code of what im trying to do. How can I do this?
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(filepath) MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited MyReader.Delimiters = New String() {","} MyReader.CommentTokens = New String() {""} MyReader.HasFieldsEnclosedInQuotes = True Dim currentRow As String() = MyReader.ReadFields While Not MyReader.EndOfData Try currentRow = MyReader.ReadFields() Dim item As ListViewItem ' Dim NameHeader As Coloumn Header ' for each header in headers if header = "name" NameHeader = currentRow(i) If currentRow.Length = 10 Then item = ListView1.Items.Add("TEST") 'item.SubItems.Add(NameHeader) item.SubItems.Add(currentRow(5)) Else End If End While End Using
I don't know how I can help you...if the header is the first row, then you should be able to read all the column headers in one shot...what problems are you having?
pgnatyuk
What do you mean CSV headers?
CSV is Coma Separated Values?
so it is a text file like:
1, Jon Smith, student, Mathematics
2, Bred Pit, student, physics
each line is a record in a table. there is the coma between the columns. There is the line feed and carriage return in the end of each line.
PockyMaster
Any reason why you are using a listview instead of a datagrid?
The way I have the code above pickes up the the students and starts at line 0 by reading John Smith ..Math etc as currentRow(0) how can using the code above pick up Name. Subject etc im trying to match Name and Subject etc with other strings to see if the document contains those specified strings I think somewhere in my code I have it that it skips to John Smith... etc