in reply to sorting a listview

Well I set-up a quick test .... basically one of your sort mechanisms seems to not be working.

I commented out the offending code and the code appears to work now. I also made some minor changes to accomodate my wrapper for variables and control names.

Since Strings and numbers are scalars you don't need to differentiate them( i think ) they can be directly compared and will sort out. I tested with random numbers, random characters and combinations it worked for all colummns so I added a column and it still worked.

I didn't examine the faulty code to trace the reason it didn't work but if you want root cause you have a starting point.

I used Gui::Loft so below is just your code with the added comments as otherwise I'd have to send you the binary gld file as well as the script.
#--------------------- Anonymonk's Code ------------------------------ sub lvwListView1_ColumnClick { #modified to match my Listview's name #######ADDED to define variables... defined(my $win = $Win32::GUI::Loft::window{winWindow1}) or return(1); $ListView = $win->lvwListView1; ################################################################# $totalcols = 7; #5 and 6 are hidden my $column = shift; $column=$column+1; if ($lastcolumn == $column) { $sortorder = 1 - $sortorder; } else { $sortorder = 0; } %data=(); ###Corrected ? wherewas this initialized in original code? $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 ###Problem in Columns 1&4 ? So comment them out No need to differenti +ate between #'s and letters in perl. =head 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 { ###Problem in Columns 1&4 ? So comment them out No need to differenti +ate between #'s and letters in perl. =cut foreach (sort { uc($sortcol{$a}) cmp uc($sortcol{$b})} keys %so +rtcol) { my @newdata = split/,/,$data{$_}; InsertListItem(@newdata); } #} } else { ## this is sorting in descending order =head 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 { =cut foreach (sort { uc($sortcol{$b}) cmp uc($sortcol{$a})} keys %so +rtcol) { 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 { #######ADDED to define variables... defined(my $win = $Win32::GUI::Loft::window{winWindow1}) or return(1); $ListView = $win->lvwListView1; ################################################################# my(@info) = @_; $ListView->InsertItem( -text => [@info[1],@info[2],@info[3],@info[4],@info +[5],@info[6],@info[7]] ); }