in reply to Mlistbox Sort

Update: Not to leave you without a pointer. What you want to do is figure out how to itemconfigure the list column headers, so that only the header clicked is configured as 'sortable', and returned to unsortaable as soon as the sort finishes. IIIYC.

Your code/problem seems like work :-) A bit of advice, relying on MListbox's built in sort with header click, will not offer you the most flexibility and control. Always store data in arrays, do sorting whatever way you want on the array, then just use the MListbox ( or whatever widget) to display the array.

Here is the only example I have to show sorting all rows, based on the values in the other rows. Other than that.... hire me and I'll make it work :-)

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::MListbox; ### Build Main Window # my $mainWindow = MainWindow->new; $mainWindow->geometry("800x600"); my $frame = $mainWindow->Frame(-bd => 2, -relief => 'raised')->pack(- +expand => 1, -fill => 'both'); my $scrolledMListbox = $frame->Scrolled( qw/ MListbox -selectmode browse -scrollbars oe / )->pack(-expand => 1, -fill => 'both'); $scrolledMListbox->columnInsert('end', -text=>'Date', -sortable=>1, +-width => 10); $scrolledMListbox->columnInsert('end', -text=>'Time', -sortable=>1, +-width => 10); $scrolledMListbox->columnInsert('end', -text=>'Property', -sortable= +>1, -width => 10); $scrolledMListbox->columnInsert('end', -text=>'Name', -sortable=>1, +-width => 10); $scrolledMListbox->columnInsert('end', -text=>'Address', -sortable=> +1, -width => 10); $scrolledMListbox->columnInsert('end', -text=>'Phone', -sortable=>1, + -width => 10); $scrolledMListbox->bindRows('<ButtonRelease-1>', sub { my ($w, $infoHR) = @_; print "@_\n"; print "You selected row: " . $infoHR->{-row} . " in column: " . $infoHR->{-column} . "\n"; print $scrolledMListbox->getRow( $scrolledMListbox->curselection +()->[0] ),"\n"; } ); for (my $count = 100; $count >= 1; $count--){ $scrolledMListbox->insert('end', [[int rand 20], [int rand 20], [ +int rand 20], [int rand 20], [int rand 20], [int rand 20]]); } MainLoop;

I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness

Replies are listed 'Best First'.
Re^2: Mlistbox Sort
by skywalker (Beadle) on Feb 18, 2009 at 17:23 UTC

    Thanks for that

    ive setup the bind to the header and then sorted the array as is, this enables me to also determine the type of sort to do on each column.

    code

    #bind to the header column, to enable sorting and also so we can distr +oy the thread $grid->bindColumns('<Button-1>' => sub { my ($w, $infoHR) = @_; my $column = $infoHR->{-column}; #change the queue status to HOLD while any user interaction is + occuring &button_setup('HOLD','Red'); #kill current processing thread print "Thread destroyed\n"; $thr->cancel(); my @entirelist = $grid->get(0,"end"); $grid->delete(0,"end"); #sort selected column if($column =~/0|2/){ @entirelist = sort {$a->[$column] <=> $b->[$column]} @enti +relist; }else{ @entirelist = sort {lc$a->[$column] cmp lc$b->[$column]} @ +entirelist; }; &populate_grid($grid,scalar @goods_issues_headers-1,\@entireli +st); });
    all I need to do now is add in reverse and its away and running.

    thanks skywalker