Fileview sort the elements by date

Post

Posted
Rating:
#1 (In Topic #1213)
Trainee
 Hello,
I would like to know how to sort the elements by date in a fileview, considering that I have a "showpreview" display.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.
Attachment
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
It can be done with a little trickery.
You can hack the IconView inside the FileView

Remember this conversation…
Gambas One - Gambas ONE

You could set the IconView "Sorted" property to false and do it yourself.
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Or a command something like this…

Code (gambas)

  1.  
  2. Public Sub SortFileViewByDate()
  3.  
  4.   Dim p As Panel = FileView1.Children[0]
  5.   Dim iv As IconView = p.Children[0]
  6.  
  7.   Dim aKeys As New String[]
  8.   Dim aDates As New Date[]
  9.  
  10.  ' make an array of the keys and an array of the modified dates...
  11.   For Each sKey As String In iv.Keys
  12.     aDates.Add(Stat(FileView1.Dir &/ iv[sKey].Text).LastModified)
  13.     aKeys.Add(sKey)
  14.   Next
  15.  
  16. ' sort the list by date, swapping keys along with dates
  17. '  (this sort function might need some work but it looks like it works to me)
  18.  
  19. ReCheck:
  20.   For c As Integer = 0 To aDates.Max - 1
  21.     If DateDiff(aDates[c], aDates[c + 1], gb.Second) > 0 Then
  22.       Swap aDates[c], aDates[c + 1]
  23.       Swap aKeys[c], aKeys[c + 1]
  24.       Goto ReCheck
  25.     Endif
  26.   Next
  27.  
  28.   ' make the IconView match the list order by going through the list in reverse moving each item key to the top of the iconview.
  29.   For c As Integer = aKeys.Max DownTo 0
  30.     iv.MoveTo(aKeys[c])
  31.     iv.Item.MoveFirst()
  32.   Next
  33.  
  34.  
  35. ' now it is in date order
  36.  
  37.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee
Many thanks for your help! It works perfectly.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

toto96 said

Many thanks for your help! It works perfectly.

No worries.

btw if you want to reverse the order just reverse the 2 arrays before moving the items…

Code (gambas)

  1.  
  2. If bReverse Then ' reverse the order to show oldest first if required
  3.   aKeys.Reverse
  4.   aDates.Reverse
  5.  
  6.   ' make the IconView match the list order
  7.  
  8.   For c As Integer = aKeys.Max DownTo 0
  9.     iv.MoveTo(aKeys[c])
  10.     iv.Item.MoveFirst()
  11.   Next
  12.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.