Click here to Skip to main content
15,881,715 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Adding/Removing values from webbrowser control context menu Pin
Dave Kreskowiak8-Apr-08 7:14
mveDave Kreskowiak8-Apr-08 7:14 
Questionusing Crystal report in vb.Net Pin
Arunava358-Apr-08 3:57
Arunava358-Apr-08 3:57 
GeneralRe: using Crystal report in vb.Net Pin
Steven J Jowett8-Apr-08 5:31
Steven J Jowett8-Apr-08 5:31 
GeneralRe: using Crystal report in vb.Net Pin
Mycroft Holmes8-Apr-08 17:17
professionalMycroft Holmes8-Apr-08 17:17 
Questionhow to sort arraylist of FileInfo objects based on file's LastAccessTime????? Pin
shraddha19048-Apr-08 2:13
shraddha19048-Apr-08 2:13 
GeneralRe: how to sort arraylist of FileInfo objects based on file's LastAccessTime????? Pin
Christian Graus8-Apr-08 2:19
protectorChristian Graus8-Apr-08 2:19 
QuestionRe: how to sort arraylist of FileInfo objects based on file's LastAccessTime????? Pin
shraddha19048-Apr-08 2:53
shraddha19048-Apr-08 2:53 
GeneralRe: how to sort arraylist of FileInfo objects based on file's LastAccessTime????? Pin
Dave Kreskowiak8-Apr-08 3:52
mveDave Kreskowiak8-Apr-08 3:52 
Well, you got the right idea, just the wrong interface in your compare class. Thanks for showing us you actually did try to get this to work. You have no idea how rare that is! Wink | ;)

The Sort method takes an instance of a class implementing IComparer, not IComparable.

Usually, you just create a small class that implements the lone Compare method defined by the interface:
Public Class FileInfoDateComparer
    Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
    Implements System.Collections.IComparer.Compare

    ' Notice that Compare takes two Objects, not FileInfo objects.  Check
    ' to see if they are both FileInfo objects first.
    If TypeOf x Is FileInfo AndAlso TypeOf y Is FileInfo Then
        ' If they are, cast the Objects back to FileInfo objects
        ' so we can use them.
        Dim op1 As FileInfo = DirectCast(x, FileInfo)
        Dim op2 As FileInfo = DirectCast(y, FileInfo)
        Return op1.LastAccessTimeUtc.CompareTo(op2.LastAccessTimeUtc)
    Else
        ' Throw an ArgumentException here because both arguements were not FileInfo objects.
    End If
End Function

And to call the sort method using this new IComparer implementation:
stableFiles.Sort(New FileInfoDateComparer)

That's it!


A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008




GeneralRe: how to sort arraylist of FileInfo objects based on file's LastAccessTime????? Pin
shraddha19048-Apr-08 4:24
shraddha19048-Apr-08 4:24 
Generalautomatically change the question in the page after 10 seconds Pin
hepsy.i8-Apr-08 0:37
hepsy.i8-Apr-08 0:37 
GeneralRe: automatically change the question in the page after 10 seconds Pin
Christian Graus8-Apr-08 0:43
protectorChristian Graus8-Apr-08 0:43 
Questioncount in vb.net..help..urgent,,thanks Pin
Member 44429168-Apr-08 0:09
Member 44429168-Apr-08 0:09 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Christian Graus8-Apr-08 0:20
protectorChristian Graus8-Apr-08 0:20 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Member 44429168-Apr-08 0:31
Member 44429168-Apr-08 0:31 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Christian Graus8-Apr-08 0:40
protectorChristian Graus8-Apr-08 0:40 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Member 44429168-Apr-08 0:54
Member 44429168-Apr-08 0:54 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Christian Graus8-Apr-08 1:12
protectorChristian Graus8-Apr-08 1:12 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Member 44429168-Apr-08 3:56
Member 44429168-Apr-08 3:56 
GeneralRe: count in vb.net..help..urgent,,thanks Pin
Christian Graus8-Apr-08 11:23
protectorChristian Graus8-Apr-08 11:23 
GeneralNew Pin
abdulnawas7-Apr-08 23:59
abdulnawas7-Apr-08 23:59 
GeneralRe: New Pin
Christian Graus8-Apr-08 0:21
protectorChristian Graus8-Apr-08 0:21 
GeneralRe: New Pin
Steven J Jowett8-Apr-08 2:05
Steven J Jowett8-Apr-08 2:05 
QuestionHow to restrict splitter bar to certain limit ? Pin
mithilesh swarge7-Apr-08 23:43
mithilesh swarge7-Apr-08 23:43 
GeneralRe: How to restrict splitter bar to certain limit ? Pin
Dave Kreskowiak8-Apr-08 3:06
mveDave Kreskowiak8-Apr-08 3:06 
GeneralRe: How to restrict splitter bar to certain limit ? Pin
mithilesh swarge10-Apr-08 3:21
mithilesh swarge10-Apr-08 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.