
sort ListView by date and time by pressing the column header
Of course theres a 3rd way, which is to load the items into the listview in
date order to start with e.g. from arecordset order it by the relevant
datecolumn before filling the listbox or view, when a user click a header,
go get the recordset again with a new sort order, or with a disconnected ado
recordset, simply resort it appropriately.
Quote:
> Right Avi,
> Theres a couple of ways to do this, theres Microsoft's and there's mine!
> God only help you if you try Microsoft's - it involves so much jiggery
pkery
> that you'll be dizzy just reading their spiel (on the MSDN Library CD) and
> in my opinon its messy and bloated.
> Try this though. Create a column in your listview to the right of the Date
> column, and fill it with the Double Data Type equivalent of the date e.g.
> for each row set it to CDbl(DateVal) for the corresponding row.
> I often do this when reading in from a SQL database by adding a column in
> the stored procedure with the Date coerced to a real number i.e. Float.
But
> you can also do it on the fly (but slower of course for large listcounts)
> like this (from a DMO utility):
> Dim NewLine As MSComctlLib.ListItem
> For rCount = 1 To numCount
> Set NewLine = .ListItems.Add(, , qrs.GetColumnString(rCount, 1))
> CurrDate =
> Format(Left$(oDb.StoredProcedures(qrs.GetColumnString(rCount,
> 1)).CreateDate, 19), "dd-mm-yy hh:mm:ss")
> NewLine.SubItems(1) = CurrDate
> NewLine.SubItems(2) = CDbl(CurrDate) <<<<<<<<<<<<< This is the
line
> you need to add
> Next rCount
> Then for both methods, make the dummy double column hidden (width =0) and
> when a user clicks on the Date column Header, add one to the ColumnHeaders
> Index in the Listview_ColumnClick event. This can make the required ASC,
> DESC logic somwhat complicated but hey, we're programmers aren't we? Any
> probs with this, get back to us
> Clive
> > Hello all.
> > I'm using VB6(SP5) in my application.
> > I'm using the ListView from the SP4(windows common control...).
> > in the ListView I have 3 columns that one of them is Date\Time.
> > I want to be able to sort the list in ascending and descending order by
> > pressing the column header(first press ascending, then
descending......).
> > any idea or solution will be appreciated.
> > Advanced thanks, Avi.