2

我将列表视图设置为详细信息以尝试创建列,但列不会显示。是什么阻止了列的显示?

Imports System.IO
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Menu


Public Class Jonathan_Roda_P4
    Dim TitlesData(21)
    Dim BOData(21)

    'Clear Button Function
    Private Sub ResetClearToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetClearToolStripMenuItem.Click
        'Clear Title LV
        DispResView.Clear()
        'Clear Box Office List
        BOList.Items.Clear()
        'Resets User Message to default
        UsrMsg.Text = "Data Not Loaded"
    End Sub

    'Help/Instructions Properties

    Private Sub InstructionsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InstructionsToolStripMenuItem.Click
        MessageBox.Show("1. Click the 'Load Files' Button" & vbNewLine _
                        & vbNewLine _
                        & "2. Select two respective files." & vbNewLine _
                        & "      (Note: Each file must have the same number of lines)" & vbNewLine _
                        & "      (Note: You may only select two files)" & vbNewLine _
                        & vbNewLine _
                        & "3. Select the 'Open' button to load your selected files" & vbNewLine _
                        & vbNewLine _
                        & "4. The Box Office Lister will now display each file's contents as it appears in the file" & vbNewLine _
                        & vbNewLine _
                        & "5. Clicking any of the sort buttons will reorder the displayed content as follows:" & vbNewLine _
                        & "       a) Sort by A-Z: Sorts the displayed content alphabetically by title" & vbNewLine _
                        & "       b) Sort by Z-A: Sorts the displayed content in reverse alphabetical order by title" & vbNewLine _
                        & "       c) Sort by 0-9: Sorts the displayed content in ascending numerical order by Box Office Amount" & vbNewLine _
                        & "       d) Sort by 9-0: Sorts the displayed content in descending numerical order by Box Office Amount" & vbNewLine _
                        & vbNewLine _
                        & "6. Clicking the 'Clear' button will reset the program and require you to select two new files" & vbNewLine _
                        & vbNewLine _
                        & "7. Clicking the 'Exit' button will close the program" & vbNewLine _
                        & vbNewLine _
                        & "8. TOP THIRD" & vbNewLine _
                        & "      Top Third lists the top 1/3 missions in order of Box Office Amount", "007 Box Office Lister Instructions")
    End Sub

    'File/Exit Properties
    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

    'Exit Button Properties
    Private Sub ExitBtn_Click(sender As Object, e As EventArgs) Handles ExitBtn.Click
        Application.Exit()
    End Sub

    Private Sub ClearBtn_Click(sender As Object, e As EventArgs) Handles ClearBtn.Click
        DispResView.Clear()
        UsrMsg.Text = "Data Not Loaded"
    End Sub

    Private Sub LoadButton_Click(sender As Object, e As EventArgs) Handles LoadButton.Click

        With OpenFileDialog1
            .CheckPathExists = True
            .DefaultExt = "txt"
            .Filter = _
             "Text files (*.txt)|*.txt"
            .Multiselect = True
            .RestoreDirectory = True
            .Title = "Open"
            .ValidateNames = True
            DispResView.Clear()
        End With
        'Resets User Message to default if another message is displayed
        UsrMsg.Text = "Data Not Loaded"

        'Sets Default folder to Desktop
        OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

        'OpenFileDialog Properties
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim count As Integer = 0
            For Each s As String In OpenFileDialog1.FileNames
                Dim sAllData() As String = System.IO.File.ReadAllLines(s)
                count = count + 1
            Next
            For Each openFile As String In OpenFileDialog1.FileNames
                Dim getAllData() As String = File.ReadAllLines(openFile)
                For i As Integer = 0 To getAllData.Length - 1
                    DispResView.Items.Add(getAllData(i))
                Next
            Next
        End If

    End Sub

    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

    End Sub
End Class
4

1 回答 1

8

您是否已将所有列标题添加到 ListView.Columns?ListView 不会显示比它的标题更多的列。

DispResView.Columns.Add "Name"
DispResView.Columns.Add "Size"
'etc.

请注意,如果您希望不删除列标题,您应该调用DispResview.Items.Clear而不是DispResView.Clear.

于 2013-03-23T01:31:24.700 回答