From: <Kev...@al...> - 2002-06-27 09:17:35
|
Mark, Haven't had time to examine your code to closely but it looks as though you're sorting everything as strings. I assume the quantity should be a number? I've used something like the code below to try to deal with this. I can send you a working example if you need it and this is your problem. Cheers, Kev. sub alpascend { uc($details{$a}[$col]) cmp uc ($details{$b}[$col]); } sub numdescend { $details{$b}[$col] <=> $details{$a}[$col]; } sub alpdescend { uc($details{$b}[$col]) cmp ($details{$a}[$col]); } sub initlv { $Window->ListView->Clear(); my $rout; @index=keys %details; $rout= $details{1}[$col]=~ /^\d/ ? "num" : "alp"; if ($dir==1) { $rout.="ascend"; } else { $rout.="descend"; } @index= sort $rout @index; foreach $i (@index) { if ($details{$i}[0] ne '..') { InsertListItem(0, $details{$i}[0], $details{$i}[1]); } else { InsertListItem(1, $details{$i}[0], $details{$i}[1]); } } $Window->ListView->SetFocus(); } sub ListView_ColumnClick { $col=shift; if ($col==$lastcol) { $dir= $dir * -1; } else { $dir= -1; } initlv($dir); $lastcol=$col; } |---------+------------------------------------------------> | | ma...@mm... | | | Sent by: | | | per...@li...ur| | | ceforge.net | | | | | | | | | 27/06/2002 07:32 | | | | |---------+------------------------------------------------> >----------------------------------------------------------------------------------------------| | | | To: per...@li... | | cc: | | Subject: [perl-win32-gui-users] sorting a listview | >----------------------------------------------------------------------------------------------| hi. i've got alist view with 4 columns, being catalogue number, artist, title and qty (there's 2 other columns but they don't matter) and i've been trying to figure out how to sort the whole listview on a column click. i found a message sometime last year where someone posted something that i kind of got working, after a bit of tweaking. the problem is that the qty column doesn't sort properly and i just can't seem to figure out why. all the other columns sort fine when i click on them. any ideas? code below thanx in advance sub ListView_ColumnClick { $totalcols = 6; my $column = shift; print "column:$column\n"; $column=$column+1; ## i do this so that I can toggle between ascending and descending sorts ## 0 = ascending (A-Z), 1 = decending (Z - A) if ($lastcolumn == $column) # if you clicked the same column twice in a row {$sortorder = 1 - $sortorder;} # toggle between 1 and 0 values else {$sortorder = 0;} print "You Clicked $column, last time it was $lastcolumn,sortorder =$sortorder\n"; $lastcolumn = $column; %data=(); $rows=$ListView->Count(); print "rows:$rows\n"; for $i(0..$rows-1) { $row=""; my %result=$ListView->GetItem($i,0); $image=$result{-image}; for $j(0..$totalcols-1) { my %result=$ListView->GetItem($i,$j); $text=$result{-text}; $row.=",$text"; } $data{$i}="$image$row"; } my %sortcol = NewList($column, %data); SortListItem(\%data,\%sortcol,$column); if ($sortorder) { print "Sorted descending by Column $column\n"; } else { print "Sorted ascending by Column $column\n"; } return; } sub SortListItem { my ($data,$sortcol,$column) = @_; my $check; my %data = %$data; my %sortcol = %$sortcol; $check = "$_" foreach (values %sortcol); $ListView->Clear(); ## clear the ListView window $index = 0; if ($sortorder == 0) { ## this is sorting in ascending order if (($column == 1) or ($column == 4)) { print "sorting numerically\n"; foreach (sort { (substr($sortcol{$a},0,index($sortcol{$a}," "))) <=> (substr($sortcol{$b},0,index($sortcol{$b}," "))) } keys %sortcol) { my @newdata = split/,/,$data{$_}; print $data{$_}; InsertListItem(@newdata); } } else { foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b}) } keys %sortcol) { my @newdata = split/,/,$data{$_}; print $data{$_}; InsertListItem(@newdata); } } $ListView->Update(); } else { ## this is sorting in descending order if (($column == 1) or ($column == 4)) { print "sorting numerically\n"; foreach (sort { (substr($sortcol{$b},0,index($sortcol{$b}," "))) <=> (substr($sortcol{$a},0,index($sortcol{$a}," "))) } keys %sortcol) { my @newdata = split/,/,$data{$_}; print $data{$_}; InsertListItem(@newdata); } } else { foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a}) } keys %sortcol) { my @newdata = split/,/,$data{$_}; print $data{$_}; InsertListItem(@newdata); } $ListView->Update(); } } my $lpPoint = pack("LLLLLALLLL", LVIF_STATE, 0, 0, 0x2000,LVIS_STATEIMAGEMASK, " ", 127, 0, 0, 0); my $rtn = $SendMsg->Call($ListView->{'-handle'}, LVM_SETITEMSTATE, -1, $lpPoint); return; } sub NewList { ## This creates another hash to use only for sorting purposes. my ($column,%sortcol) = @_; my $sortthis; foreach (keys %sortcol) { my @info = split /,/, $sortcol{$_}; $sortthis = $info[$column]; $sortcol{$_} = "$sortthis"; } return(%sortcol); } sub InsertListItem { my(@info) = @_; $Window->ListView->InsertItem( #-item => $Window->ListView->Count(), -text => [@info[1],@info[2],@info[3],@info[4], @info[5],@info[6]], ); #$Window->ListView->SetItem( # -item => $item, # -subitem => 1, # -text => $description, # ); print "@info[1] @info[2] @info[3] @info[4] @info[5] @info[6]\n"; } ------------------------------------------------------- Sponsored by: ThinkGeek at http://www.ThinkGeek.com/ _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users |
From: Frazier, J. J. <Joe...@Pe...> - 2002-06-27 15:32:17
|
Here is what I use. I have "global" vars called $dir and $sortCol. = $dir contains the current direction (asc or desc), while $sortCol = contains the last sorted column. Using both, I then either reverse the = sort is the column is the same as the current sorted column, or apply a = asc sort if it is a new column. sub lvwJobposts_ColumnClick{ my $sort =3D shift; #column to sort on, passed in by the click event = and is the header you click on. my @Rows; for(my $x =3D 0; $x < $win->lvwJobposts->Count();$x++){ my @Values; for(my $y =3D 0; $y <=3D $win->lvwJobposts->{Columns}; $y++){ my %data =3D $win->lvwJobposts->ItemInfo($x, $y); push @Values, $data{-text}; } push @Rows, \@Values; =20 =3Dpod this grabs all the columns in a row and stuffs into an array subscript, = then go to the next array subscript and do the same thing again. After = this loop, @Rows is a 2 diminsional array like this: [joe, frazier, 30, tammy], [john, smith, 35, ''], [bill, wilson, 40, Cary] where the columns are laid out like "firstname, lastname, age, wife". =3Dcut=09 } if ($sort =3D=3D $sortCol){ if($dir eq 'f'){ $dir =3D 'b'; }elsif($dir eq 'b'){ $dir =3D 'f'; } }else{ $sortCol =3D $sort; $dir =3D "f"; } my @result; dosort (\@Rows, \@result, $sort, $dir); $win->lvwJobposts->Clear(); for (my $d =3D 0; $d <=3D $#result;$d++){ Win32::GUI::DoEvents(); $win->lvwJobposts->InsertItem(-text =3D>$result[$d]); } } sub dosort { # dosort \@sort, \@result, column 0 to n, 'f'|'r' my ($sort, $sorted, $col, $dir) =3D @_; if ($dir eq 'f') { @$sorted =3D sort { $a->[$col] <=3D> $b->[$col] || $a->[$col] cmp = $b->[$col] } @$sort; } else { @$sorted =3D sort { $b->[$col] <=3D> $a->[$col] || $b->[$col] cmp = $a->[$col] } @$sort; } } This could be cleaned up and made shorter, but It works great and I dont = have time to mess with it right now. Perhaps Aldo can put something in = the core Win32 to handle all this junk for us at some point in the = future. Joe > -----Original Message----- > From: ma...@mm... [mailto:ma...@mm...] > Sent: Thursday, June 27, 2002 2:32 AM > To: per...@li... > Subject: [perl-win32-gui-users] sorting a listview >=20 >=20 > hi. i've got alist view with 4 columns, being catalogue=20 > number, artist, > title and qty (there's 2 other columns but they don't matter)=20 > and i've been > trying to figure out how to sort the whole listview on a=20 > column click. i > found a message sometime last year where someone posted=20 > something that i > kind of got working, after a bit of tweaking. the problem is=20 > that the qty > column doesn't sort properly and i just can't seem to figure=20 > out why. all > the other columns sort fine when i click on them. any ideas?=20 > code below >=20 > thanx in advance >=20 >=20 > sub ListView_ColumnClick { > $totalcols =3D 6; > my $column =3D shift; > print "column:$column\n"; > $column=3D$column+1; >=20 > ## i do this so that I can toggle between ascending and descending > sorts > ## 0 =3D ascending (A-Z), 1 =3D decending (Z - A) > if ($lastcolumn =3D=3D $column) # if you clicked the same=20 > column twice in > a row > {$sortorder =3D 1 - $sortorder;} # toggle between 1=20 > and 0 values > else > {$sortorder =3D 0;} > print "You Clicked $column, last time it was=20 > $lastcolumn,sortorder > =3D$sortorder\n"; > $lastcolumn =3D $column; >=20 > %data=3D(); > $rows=3D$ListView->Count(); > print "rows:$rows\n"; > for $i(0..$rows-1) > { > $row=3D""; > my %result=3D$ListView->GetItem($i,0); > $image=3D$result{-image}; > for $j(0..$totalcols-1) > { > my %result=3D$ListView->GetItem($i,$j); > $text=3D$result{-text}; > $row.=3D",$text"; > } > $data{$i}=3D"$image$row"; > } >=20 > my %sortcol =3D NewList($column, %data); > SortListItem(\%data,\%sortcol,$column); > if ($sortorder) { > print "Sorted descending by Column $column\n"; > } else { > print "Sorted ascending by Column $column\n"; > } > return; > } >=20 > sub SortListItem { > my ($data,$sortcol,$column) =3D @_; > my $check; > my %data =3D %$data; > my %sortcol =3D %$sortcol; >=20 > $check =3D "$_" foreach (values %sortcol); >=20 > $ListView->Clear(); ## clear the ListView window > $index =3D 0; > if ($sortorder =3D=3D 0) > { ## this is sorting in ascending order > if (($column =3D=3D 1) or ($column =3D=3D 4)) > { > print "sorting numerically\n"; > foreach (sort { > (substr($sortcol{$a},0,index($sortcol{$a}," "))) = <=3D> > =20 > (substr($sortcol{$b},0,index($sortcol{$b}," "))) } > keys %sortcol) > { > my @newdata =3D split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > else { > foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b}) > } keys %sortcol) > { > my @newdata =3D split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > $ListView->Update(); > } > else > { ## this is sorting in descending order > if (($column =3D=3D 1) or ($column =3D=3D 4)) > { > print "sorting numerically\n"; > foreach (sort { > (substr($sortcol{$b},0,index($sortcol{$b}," "))) <=3D> > (substr($sortcol{$a},0,index($sortcol{$a}," "))) } keys > %sortcol) > { > my @newdata =3D split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > else { > foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a}) > } keys %sortcol) > { > my @newdata =3D split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > $ListView->Update(); > } > } > my $lpPoint =3D pack("LLLLLALLLL", LVIF_STATE, 0, 0, > 0x2000,LVIS_STATEIMAGEMASK, " ", 127, 0, 0, 0); > my $rtn =3D $SendMsg->Call($ListView->{'-handle'},=20 > LVM_SETITEMSTATE, -1, > $lpPoint); >=20 > return; > } >=20 > sub NewList { > ## This creates another hash to use only for sorting purposes. > my ($column,%sortcol) =3D @_; > my $sortthis; >=20 > foreach (keys %sortcol) { > my @info =3D split /,/, $sortcol{$_}; > $sortthis =3D $info[$column]; > $sortcol{$_} =3D "$sortthis"; > } > return(%sortcol); > } >=20 > sub InsertListItem { > my(@info) =3D @_; > $Window->ListView->InsertItem( > #-item =3D> $Window->ListView->Count(), > -text =3D> = [@info[1],@info[2],@info[3],@info[4], > @info[5],@info[6]], > ); > #$Window->ListView->SetItem( > # -item =3D> $item, > # -subitem =3D> 1, > # -text =3D> $description, > # ); > print "@info[1] @info[2] @info[3] @info[4] @info[5] @info[6]\n"; > } >=20 >=20 >=20 > ------------------------------------------------------- > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users >=20 |
From: <ma...@mm...> - 2002-06-28 05:43:27
|
thanx for all the replies. i think i'll just stick with what i'm using at the moment and see if i can figure out where its going wrong. on a different note, is it possible to put a copyright symbol in the window title? AND i was just going through the samples and i noticed in pmx.pl that the menu accelerators actually work, so i added the & in front of menu items in my program but it doesn't work for the top menu entry. so if i press alt+f for file nothing will happen but if i click on file and press s the settings window will appear. any ideas? thanx in advance Mark Di Nicola <amo...@ih...> Sent by: To: Kev...@al... per...@li...urc cc: eforge.net per...@li..., per...@li... Subject: Re: [perl-win32-gui-users] sorting a 27/06/02 08:26 PM listview Kev...@al... wrote: > Mark, > > Haven't had time to examine your code to closely but it looks as though > you're sorting everything as strings. I assume the quantity should be a > number? > > I've used something like the code below to try to deal with this. I can > send you a working example if you need it and this is your problem. > > Cheers, > > Kev. > > sub alpascend { > uc($details{$a}[$col]) cmp uc ($details{$b}[$col]); > } > > sub numdescend { > $details{$b}[$col] <=> $details{$a}[$col]; > } > > sub alpdescend { > uc($details{$b}[$col]) cmp ($details{$a}[$col]); > } > > sub initlv { > $Window->ListView->Clear(); > my $rout; > > @index=keys %details; > $rout= $details{1}[$col]=~ /^\d/ ? "num" : "alp"; > > if ($dir==1) { > $rout.="ascend"; > } else { > $rout.="descend"; > } > > @index= sort $rout @index; > > foreach $i (@index) { > if ($details{$i}[0] ne '..') { > InsertListItem(0, $details{$i}[0], $details{$i}[1]); > } else { > InsertListItem(1, $details{$i}[0], $details{$i}[1]); > } > } > $Window->ListView->SetFocus(); > } > > sub ListView_ColumnClick { > $col=shift; > if ($col==$lastcol) { > $dir= $dir * -1; > } else { > $dir= -1; > } > initlv($dir); > $lastcol=$col; > } > > > > |---------+------------------------------------------------> > | | ma...@mm... | > | | Sent by: | > | | per...@li...ur| > | | ceforge.net | > | | | > | | | > | | 27/06/2002 07:32 | > | | | > |---------+------------------------------------------------> > > ----------------------------------------------------------------------------------------------| > | | > | To: per...@li... | > | cc: | > | Subject: [perl-win32-gui-users] sorting a listview | > > ----------------------------------------------------------------------------------------------| > > > > > hi. i've got alist view with 4 columns, being catalogue number, artist, > title and qty (there's 2 other columns but they don't matter) and i've been > trying to figure out how to sort the whole listview on a column click. i > found a message sometime last year where someone posted something that i > kind of got working, after a bit of tweaking. the problem is that the qty > column doesn't sort properly and i just can't seem to figure out why. all > the other columns sort fine when i click on them. any ideas? code below > > thanx in advance > > > sub ListView_ColumnClick { > $totalcols = 6; > my $column = shift; > print "column:$column\n"; > $column=$column+1; > > ## i do this so that I can toggle between ascending and descending > sorts > ## 0 = ascending (A-Z), 1 = decending (Z - A) > if ($lastcolumn == $column) # if you clicked the same column twice in > a row > {$sortorder = 1 - $sortorder;} # toggle between 1 and 0 values > else > {$sortorder = 0;} > print "You Clicked $column, last time it was $lastcolumn,sortorder > =$sortorder\n"; > $lastcolumn = $column; > > %data=(); > $rows=$ListView->Count(); > print "rows:$rows\n"; > for $i(0..$rows-1) > { > $row=""; > my %result=$ListView->GetItem($i,0); > $image=$result{-image}; > for $j(0..$totalcols-1) > { > my %result=$ListView->GetItem($i,$j); > $text=$result{-text}; > $row.=",$text"; > } > $data{$i}="$image$row"; > } > > my %sortcol = NewList($column, %data); > SortListItem(\%data,\%sortcol,$column); > if ($sortorder) { > print "Sorted descending by Column $column\n"; > } else { > print "Sorted ascending by Column $column\n"; > } > return; > } > > sub SortListItem { > my ($data,$sortcol,$column) = @_; > my $check; > my %data = %$data; > my %sortcol = %$sortcol; > > $check = "$_" foreach (values %sortcol); > > $ListView->Clear(); ## clear the ListView window > $index = 0; > if ($sortorder == 0) > { ## this is sorting in ascending order > if (($column == 1) or ($column == 4)) > { > print "sorting numerically\n"; > foreach (sort { > (substr($sortcol{$a},0,index($sortcol{$a}," "))) <=> > (substr($sortcol{$b},0,index($sortcol{$b}," "))) } > keys %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > else { > foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b}) > } keys %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > $ListView->Update(); > } > else > { ## this is sorting in descending order > if (($column == 1) or ($column == 4)) > { > print "sorting numerically\n"; > foreach (sort { > (substr($sortcol{$b},0,index($sortcol{$b}," "))) <=> > (substr($sortcol{$a},0,index($sortcol{$a}," "))) } keys > %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > else { > foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a}) > } keys %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > $ListView->Update(); > } > } > my $lpPoint = pack("LLLLLALLLL", LVIF_STATE, 0, 0, > 0x2000,LVIS_STATEIMAGEMASK, " ", 127, 0, 0, 0); > my $rtn = $SendMsg->Call($ListView->{'-handle'}, LVM_SETITEMSTATE, -1, > $lpPoint); > > return; > } > > sub NewList { > ## This creates another hash to use only for sorting purposes. > my ($column,%sortcol) = @_; > my $sortthis; > > foreach (keys %sortcol) { > my @info = split /,/, $sortcol{$_}; > $sortthis = $info[$column]; > $sortcol{$_} = "$sortthis"; > } > return(%sortcol); > } > > sub InsertListItem { > my(@info) = @_; > $Window->ListView->InsertItem( > #-item => $Window->ListView->Count(), > -text => [@info[1],@info[2],@info[3],@info[4], > @info[5],@info[6]], > ); > #$Window->ListView->SetItem( > # -item => $item, > # -subitem => 1, > # -text => $description, > # ); > print "@info[1] @info[2] @info[3] @info[4] @info[5] @info[6]\n"; > } > > > > ------------------------------------------------------- > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > > > > > > ------------------------------------------------------- > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > > kevin if you're talking about using cmp instead of <=> then thats not it. depending on which column it is, it will use either of those 2. so for 1 and 4 (cat number and qty) it uses <=> and for anything else it uses cmp. sorting the cat number works perfectly but for qty it doesn't for some reason. mark ------------------------------------------------------- Sponsored by: ThinkGeek at http://www.ThinkGeek.com/ _______________________________________________ Perl-Win32-GUI-Users mailing list Per...@li... https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users |
From: Mark Di N. <amo...@ih...> - 2002-06-27 10:27:37
|
Kev...@al... wrote: > Mark, > > Haven't had time to examine your code to closely but it looks as though > you're sorting everything as strings. I assume the quantity should be a > number? > > I've used something like the code below to try to deal with this. I can > send you a working example if you need it and this is your problem. > > Cheers, > > Kev. > > sub alpascend { > uc($details{$a}[$col]) cmp uc ($details{$b}[$col]); > } > > sub numdescend { > $details{$b}[$col] <=> $details{$a}[$col]; > } > > sub alpdescend { > uc($details{$b}[$col]) cmp ($details{$a}[$col]); > } > > sub initlv { > $Window->ListView->Clear(); > my $rout; > > @index=keys %details; > $rout= $details{1}[$col]=~ /^\d/ ? "num" : "alp"; > > if ($dir==1) { > $rout.="ascend"; > } else { > $rout.="descend"; > } > > @index= sort $rout @index; > > foreach $i (@index) { > if ($details{$i}[0] ne '..') { > InsertListItem(0, $details{$i}[0], $details{$i}[1]); > } else { > InsertListItem(1, $details{$i}[0], $details{$i}[1]); > } > } > $Window->ListView->SetFocus(); > } > > sub ListView_ColumnClick { > $col=shift; > if ($col==$lastcol) { > $dir= $dir * -1; > } else { > $dir= -1; > } > initlv($dir); > $lastcol=$col; > } > > > > |---------+------------------------------------------------> > | | ma...@mm... | > | | Sent by: | > | | per...@li...ur| > | | ceforge.net | > | | | > | | | > | | 27/06/2002 07:32 | > | | | > |---------+------------------------------------------------> > >----------------------------------------------------------------------------------------------| > | | > | To: per...@li... | > | cc: | > | Subject: [perl-win32-gui-users] sorting a listview | > >----------------------------------------------------------------------------------------------| > > > > > hi. i've got alist view with 4 columns, being catalogue number, artist, > title and qty (there's 2 other columns but they don't matter) and i've been > trying to figure out how to sort the whole listview on a column click. i > found a message sometime last year where someone posted something that i > kind of got working, after a bit of tweaking. the problem is that the qty > column doesn't sort properly and i just can't seem to figure out why. all > the other columns sort fine when i click on them. any ideas? code below > > thanx in advance > > > sub ListView_ColumnClick { > $totalcols = 6; > my $column = shift; > print "column:$column\n"; > $column=$column+1; > > ## i do this so that I can toggle between ascending and descending > sorts > ## 0 = ascending (A-Z), 1 = decending (Z - A) > if ($lastcolumn == $column) # if you clicked the same column twice in > a row > {$sortorder = 1 - $sortorder;} # toggle between 1 and 0 values > else > {$sortorder = 0;} > print "You Clicked $column, last time it was $lastcolumn,sortorder > =$sortorder\n"; > $lastcolumn = $column; > > %data=(); > $rows=$ListView->Count(); > print "rows:$rows\n"; > for $i(0..$rows-1) > { > $row=""; > my %result=$ListView->GetItem($i,0); > $image=$result{-image}; > for $j(0..$totalcols-1) > { > my %result=$ListView->GetItem($i,$j); > $text=$result{-text}; > $row.=",$text"; > } > $data{$i}="$image$row"; > } > > my %sortcol = NewList($column, %data); > SortListItem(\%data,\%sortcol,$column); > if ($sortorder) { > print "Sorted descending by Column $column\n"; > } else { > print "Sorted ascending by Column $column\n"; > } > return; > } > > sub SortListItem { > my ($data,$sortcol,$column) = @_; > my $check; > my %data = %$data; > my %sortcol = %$sortcol; > > $check = "$_" foreach (values %sortcol); > > $ListView->Clear(); ## clear the ListView window > $index = 0; > if ($sortorder == 0) > { ## this is sorting in ascending order > if (($column == 1) or ($column == 4)) > { > print "sorting numerically\n"; > foreach (sort { > (substr($sortcol{$a},0,index($sortcol{$a}," "))) <=> > (substr($sortcol{$b},0,index($sortcol{$b}," "))) } > keys %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > else { > foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b}) > } keys %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > $ListView->Update(); > } > else > { ## this is sorting in descending order > if (($column == 1) or ($column == 4)) > { > print "sorting numerically\n"; > foreach (sort { > (substr($sortcol{$b},0,index($sortcol{$b}," "))) <=> > (substr($sortcol{$a},0,index($sortcol{$a}," "))) } keys > %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > } > else { > foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a}) > } keys %sortcol) > { > my @newdata = split/,/,$data{$_}; > print $data{$_}; > InsertListItem(@newdata); > } > $ListView->Update(); > } > } > my $lpPoint = pack("LLLLLALLLL", LVIF_STATE, 0, 0, > 0x2000,LVIS_STATEIMAGEMASK, " ", 127, 0, 0, 0); > my $rtn = $SendMsg->Call($ListView->{'-handle'}, LVM_SETITEMSTATE, -1, > $lpPoint); > > return; > } > > sub NewList { > ## This creates another hash to use only for sorting purposes. > my ($column,%sortcol) = @_; > my $sortthis; > > foreach (keys %sortcol) { > my @info = split /,/, $sortcol{$_}; > $sortthis = $info[$column]; > $sortcol{$_} = "$sortthis"; > } > return(%sortcol); > } > > sub InsertListItem { > my(@info) = @_; > $Window->ListView->InsertItem( > #-item => $Window->ListView->Count(), > -text => [@info[1],@info[2],@info[3],@info[4], > @info[5],@info[6]], > ); > #$Window->ListView->SetItem( > # -item => $item, > # -subitem => 1, > # -text => $description, > # ); > print "@info[1] @info[2] @info[3] @info[4] @info[5] @info[6]\n"; > } > > > > ------------------------------------------------------- > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > > > > > > ------------------------------------------------------- > Sponsored by: > ThinkGeek at http://www.ThinkGeek.com/ > _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > > kevin if you're talking about using cmp instead of <=> then thats not it. depending on which column it is, it will use either of those 2. so for 1 and 4 (cat number and qty) it uses <=> and for anything else it uses cmp. sorting the cat number works perfectly but for qty it doesn't for some reason. mark |