sort ListView by date and time by pressing the column header 
Author Message
 sort ListView by date and time by pressing the column header

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.



Sun, 26 Sep 2004 15:22:34 GMT  
 sort ListView by date and time by pressing the column header


Fri, 19 Jun 1992 00:00:00 GMT  
 sort ListView by date and time by pressing the column header
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


Quote:
> 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.



Mon, 27 Sep 2004 07:41:49 GMT  
 sort ListView by date and time by pressing the column header


Fri, 19 Jun 1992 00:00:00 GMT  
 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.



Fri, 01 Oct 2004 09:34:05 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to sort on a listview column header?

2. sort a listview by column header click

3. ListView: column header sort mark

4. List View click on header to sort date column

5. ListView - How to sort by numeric/date and hide columns

6. Sort Listview Column By Date

7. Sorting Listview Column With Date

8. ListView: Sort Size and Date Columns

9. how to sort a date or number column in a listview report mode

10. Sorting ListView by a column with numbers/dates

11. Sorting ListView columns by DATE

12. Sorting ListView by Date Column

 

 
Powered by phpBB® Forum Software