CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    [RESOLVED] Isn't there an easy way to sort a ListView by 1 column with Visual Studio 2012

    I am using Visual Studio 2012 Express.

    I have a form with a ListView control on it. It has the following columns: Name, Date / Time created, Type, Size Name:  Form5.jpg
Views: 78
Size:  17.3 KB
    When the form opens, it gets all of the LOG (.txt) files from a certain directory and populates the ListView.

    The LOG files are usually created at different dates and times.
    When the ListView is populated, I would like to sort ONLY by Date / Time created.

    I don't want the user to be able to click on column headers to change the sorting.
    I have seen LOTS of code to do this but most of what I have seen involves multiple column sorting and creating another whole class just
    to achieve something (I think should be) so simple.

    I have included what I know how to do.

    Code:
    Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            
            Button1.Enabled = IIf(ComboBox1.Text <> Nothing, True, False)
            ComboBox1.Items.Clear()
            ListView1.Items.Clear()
            ListView1.SelectedItems.Clear()
            singleItem = Nothing
    
            For Each fName As String In My.Computer.FileSystem.GetFiles(LogFilePath)
                Dim wrditem As New ListViewItem
                Dim DatMod As String = Format(System.IO.File.GetLastWriteTime(fName), "M/d/yyyy h:mm tt")
                Dim TempType As String = My.Computer.FileSystem.GetFileInfo(fName).Extension
                Dim dPlace As Integer = InStr(TempType, ".")
                Dim FType As String = UCase(Mid(TempType, (dPlace + 1), 3))
                Dim FSize As Integer = CInt(My.Computer.FileSystem.GetFileInfo(fName).Length) / 1024
    
                wrditem.Font = New Font(wrditem.Font, FontStyle.Regular)
                wrditem.Font = New Font(wrditem.Font.FontFamily, 10)
    
                wrditem.Text = IO.Path.GetFileName(fName)
                ListView1.Items.Add(wrditem)
                wrditem.SubItems.Add(DatMod)
                wrditem.SubItems.Add(FType)
                wrditem.SubItems.Add(Str(FSize) & "K")
    
                ComboBox1.Items.Add(IO.Path.GetFileName(fName))
            Next
    
        End Sub

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Isn't there an easy way to sort a ListView by 1 column with Visual Studio 2012

    Could this example help you?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2020
    Posts
    1

    Re: Isn't there an easy way to sort a ListView by 1 column with Visual Studio 2012

    Interesting

  4. #4
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Isn't there an easy way to sort a ListView by 1 column with Visual Studio 2012

    I saw this. I was hoping for a solution that wasn't a page long.
    Sorry I bugged you. Thank you for replying

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured