从csv文件导入Listview问题

时间:2015-05-05 20:03:10

标签: vb.net listview csv

我正在创建一个从CSV文件中导入数据的列表视图窗口,我从CSV文件中创建了列标题,并确保如果它们被移动到不同的列,它也会创建它们,让我们说像

主题|目录|部分-------------->目录|主题|节

Try
        fileIn = New StreamReader(strFileIn)
        i = 0
        If Not fileIn.EndOfStream Then
            'CREATES COLUMN HEADERS OUT OF THE CSV FILE, IT WILL ONLY LOOK FOR THESE ITEMS, 
            'CHANGING THE COLUMN HEADERS IN THE CSV FILE WILL NOT AFFECT THE PROGRAM (UNLESS THE NAME IS CHANGED COMPLETELY FROM WHAT IT IS BELOW)
            strLineIn = fileIn.ReadLine
            strFields = strLineIn.Split(","c)
            For i = 0 To strFields.Length - 1
                Select Case strFields(i).ToString
                    Case "Subject"
                        lvwSchedule.Columns.Add(strFields(i))
                    Case "Catalog"
                        lvwSchedule.Columns.Add(strFields(i))
                    Case "Section"
                        lvwSchedule.Columns.Add(strFields(i))
                    Case Else
                        'nothing yet
                End Select
            Next
'Here's what's in the file
'Term   Acad Group  Acad Org    Class Nbr   Subject Catalog Section
'1151   CARTA       ARCHTEC-2   10006       ARC     1132    U01

'Here's where i'm trying to populate
' While Not fileIn.EndOfStream
            strLineIn = fileIn.ReadLine
            strFields = strLineIn.Split(","c)
            Dim lviRow As New ListViewItem(strFields(0))


            For i = 1 To strFields.Length - 1
                    Dim lsiCol As New ListViewItem.ListViewSubItem
                    lsiCol.Text = strFields(i)
                    lviRow.SubItems.Add(lsiCol)
            Next

            'THIS ADDS THE ROW TO THE ListView CONTROL
            lvwSchedule.Items.Add(lviRow)
        End While
End try

但是当我加载文件时,它给了我

主题|目录|部分< -----这是正确的

1151 CARTA ARCTEC-2< -----这是错的

我理解为什么会这样,但我一直在寻找正确的方法来跳过一个专栏,

有人能帮助我吗?此外,这不是家庭作业。

0 个答案:

没有答案