I work in VB.net only. I cal read an entire file in one statement, sort it with another statement and write it bacl in another. Three statements to sort a csv file! This is aswome, but I wan to know how to sort the file on different columns. Here is my code,

 Dim codes(), Saveline As String
        'Read/Write file data
        codes = File.ReadAllLines(FileName)
        'Save sorted copy
        Saveline = codes(0)
        codes(0) = ""
        codes(0) = Saveline
        File.WriteAllLines(FileName, codes)

What I want to do is use array.sort(codes,2)
where the 2 is column 2 or any other column. Obviously this doesnt work or I wouldn't be here. Is there a way to do this with the Array call?


8 Months
Discussion Span
Last Post by paul_61

I don't know about the array method but you might read it into a ListView then see here for how to do a custom sort on any column.


Another suggestion would be a DataGridView which has the ability to sort the data by any column. With a DataTable as the data source you have the option to save/read the data to/from xml formatted text file.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.