June 22, 2024, 09:32:50 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Listview multi column sort

Started by Andy, October 18, 2013, 12:55:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

I have a listview:

'Holiday list view box
CONTROL f3,@LISTVIEW,"",600,35,180,150,@VSCROLL|@LVSSORTASCENDING|@CTLISTNOTIFY,747

CONTROLCMD f3,747,@LVINSERTCOLUMN,0,"Holiday dates"
CONTROLCMD f3,747,@LVINSERTCOLUMN,1,"days"
CONTROLCMD f3, 747, @LVSETCOLWIDTH, 0, 120
CONTROLCMD f3, 747, @LVSETCOLWIDTH, 1, 50

Where f3 is the window, 747 is the listview.

How can I get both columns to match up?

e.g. of the data:

Holiday date   Days
05-10-2013      5
12-08-2013      3
08-08-2013      2

If i use the @LVSSORTASCENDING to sort the holiday date, the "Days" column does not correspond to the correct date.

e.g.
08-08-2013      5   
12-08-2013      3
05-10-2013      2

Is there a way I can do this?

if there is only one column, then @LVSSORTASCENDING works fine for the dates.

Thanks,
Andy.



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

The trick is in how you go about adding entries to the Listview.
The following assumes each date is unique

CONTROL f3,@LISTVIEW,"",600,35,180,150,@VSCROLL|@LVSSORTASCENDING|@CTLISTNOTIFY,747

CONTROLCMD f3,747,@LVINSERTCOLUMN,0,"Holiday dates"
CONTROLCMD f3,747,@LVINSERTCOLUMN,1,"days"
CONTROLCMD f3, 747, @LVSETCOLWIDTH, 0, 120
CONTROLCMD f3, 747, @LVSETCOLWIDTH, 1, 50

string indate,indays
indate ="05-10-2013"
indays="5"
int pos=0,position

'this will be a loop
CONTROLCMD f3,747,@LVINSERTITEM,pos,indate
position = CONTROLCMD( f3,747, @LVFINDITEM, indate)
CONTROLCMD f3,747,@LVSETTEXT,position,1,indays
pos++   'this is so we are always adding to the end of the list initially
'grab the next data and go through the loop again
'end of the loop

You should be able to make it work from this
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Yes I will try that.

I came up with an idea and it works - see attached code.

it uses 2 listviews - one on screen and one "hidden".

The later is sorted and the populates the first listbox (visable).

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.