-
December 30th, 2020, 02:39 PM
#1
[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
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
-
December 30th, 2020, 05:07 PM
#2
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
-
December 30th, 2020, 08:55 PM
#3
Re: Isn't there an easy way to sort a ListView by 1 column with Visual Studio 2012
-
January 1st, 2021, 02:43 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|