Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to convert a Files date so it can be sorted in a datagridview

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
This code gets the file name and date and populates two columns in a datagridview. but when I click the column heading to sort in date order it sorts like text since it is text. How to I convert the date into something the grid will sort like a real date? Or can I? its in red below
FileDate = fi.CreationTime.ToString
also need to conver it so the

Code:
        Dim Path As String
        Path = "\\Foc01\SharedDir\Church\Announcements\old pdf announcements"

        Dim strFileSize As String = ""
        Dim di As New IO.DirectoryInfo(Path)
        Dim aryFi As IO.FileInfo() = di.GetFiles("*.pdf")
        Dim fi As IO.FileInfo
        Dim i As Integer
        Dim arrayFileList(300)
        Dim arrayFileCreatedDate(300)

        i = 0
        For Each fi In aryFi
            [COLOR=red][b]FileDate = fi.CreationTime.To a Date???[/b][/color]
            DataGridView1.Rows.Add(fi.Name, FileDate)

        Next

DougP
 
This should do it:

FileDate = CType(fi.CreationTime, Date)

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Getting error
on that line. and xxx.ToString does not work either

Value of type 'Date' cannot be converted to 'System.Windows.Forms.DataGridViewTextBoxColumn'.

FYI Postjebenson, your Talk like a Pirate day has one too many http's.
http://http//

DougP
 
Opps my bad I need to have a DIM > Dim FileDate As Date

I also had trouble with the above code doing nothing?
I was trying something else so now this is what I have.
Is there a way to sort the date columns Descending so the most recent file is on top?

Code:
        Dim Path As String = "C:\FTPUpload\"
        Dim FileDate As Date
        'path = "\\Foc01\SharedDir\Church\Announcements\old pdf announcements"

        Dim di As New IO.DirectoryInfo(Path)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo

        For Each dra In diar1
            FileDate = CType(dra.CreationTime, Date)
            Me.DataGridView1.Rows.Add(dra.Name, FileDate)
        Next
[/code

DougP
 
this drives me nuts everything I get or type or try just creates yet another error?
Spend hours futzing with one stinking line of code.
I just want to sort a column
runtime Error
Message=Value cannot be null.
Parameter name: dataGridViewColumn
Code:
        Dim Path As String = "C:\FTPUpload\"
        


        Dim FileDate As Date
        Dim direction As ListSortDirection

        Dim di As New IO.DirectoryInfo(Path)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo

        For Each dra In diar1
            FileDate = CType(dra.CreationTime, Date)
            Me.DataGridView1.Rows.Add(dra.Name, FileDate)
        Next

        direction = ListSortDirection.Descending

        'date is the second column over

        [COLOR=red]DataGridView1.Sort(DataGridView1.Columns("Date"), direction)[/color]
        'DataGridView1.HeaderCell.SortGlyphDirection = SortOrder.Ascending

DougP
 
Hmmm...the site seems to be putting an extra " in the link, and I can't get it to stop. :/

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top