Hello,
I would like to know how to sort the elements by date in a fileview, considering that I have a "showpreview" display.
Fileview sort the elements by date
- cogier
- Site Admin
- Posts: 1127
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Fileview sort the elements by date
I can't see a way to do this using FileView, but you might consider creating your own file display to do this. Have a look at attached, there is a lot more you could do with it, but I hope it's a start.
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Fileview sort the elements by date
It can be done with a little trickery.
You can hack the IconView inside the FileView
Remember this conversation...
https://forum.gambas.one/viewtopic.php?t=1532
You could set the IconView "Sorted" property to false and do it yourself.
You can hack the IconView inside the FileView
Remember this conversation...
https://forum.gambas.one/viewtopic.php?t=1532
You could set the IconView "Sorted" property to false and do it yourself.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Fileview sort the elements by date
Or a command something like this...
Public Sub SortFileViewByDate()
Dim p As Panel = FileView1.Children[0]
Dim iv As IconView = p.Children[0]
Dim aKeys As New String[]
Dim aDates As New Date[]
' make an array of the keys and an array of the modified dates...
For Each sKey As String In iv.Keys
aDates.Add(Stat(FileView1.Dir &/ iv[sKey].Text).LastModified)
aKeys.Add(sKey)
Next
' sort the list by date, swapping keys along with dates
' (this sort function might need some work but it looks like it works to me)
ReCheck:
For c As Integer = 0 To aDates.Max - 1
If DateDiff(aDates[c], aDates[c + 1], gb.Second) > 0 Then
Swap aDates[c], aDates[c + 1]
Swap aKeys[c], aKeys[c + 1]
Goto ReCheck
Endif
Next
' make the IconView match the list order by going through the list in reverse moving each item key to the top of the iconview.
For c As Integer = aKeys.Max DownTo 0
iv.MoveTo(aKeys[c])
iv.Item.MoveFirst()
Next
End
' now it is in date order
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Fileview sort the elements by date
Many thanks for your help! It works perfectly.
- BruceSteers
- Posts: 1581
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Fileview sort the elements by date
No worries.
btw if you want to reverse the order just reverse the 2 arrays before moving the items...
If bReverse Then ' reverse the order to show oldest first if required
aKeys.Reverse
aDates.Reverse
Endif
' make the IconView match the list order
For c As Integer = aKeys.Max DownTo 0
iv.MoveTo(aKeys[c])
iv.Item.MoveFirst()
Next
If at first you don't succeed , try doing something differently.
BruceS
BruceS