sub ListView_ColumnClick { $totalcols = 6; #5 and 6 are hidden my $column = shift; $column=$column+1; if ($lastcolumn == $column) { $sortorder = 1 - $sortorder; } else { $sortorder = 0; } %data=(); $rows=$ListView->Count(); 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)) { foreach (sort{(substr($sortcol{$a},0,index($sortcol{$a}," "))) <=> (substr($sortcol{$b},0,index($sortcol{$b}," "))) } keys %sortcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } else { foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b})} keys %sortcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } } else { ## this is sorting in descending order if (($column == 1) or ($column == 4)) { foreach (sort {(substr($sortcol{$b},0,index($sortcol{$b}," "))) <=> (substr($sortcol{$a},0,index($sortcol{$a}," "))) } keys %sortcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } else { foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a})} keys %sortcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } } } return; } sub NewList { 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( -text => [@info[1],@info[2],@info[3],@info[4],@info[5],@info[6]], ); }