From: Mattia B. <mb...@ds...> - 2002-08-26 19:08:14
|
> hello > i whish to sort my ListCtrlItems. > the ListCtrl is in report mode. > > i noticed the SortItems function, but it only sorts the items after the > ItemData, not after the labels. > is there a function/a way to sort the items after the text? Not directly, see below > if not, what would be a good/fast way do do this myself? > think that's a very mathematically problem. I don't kno how fast is what I am proposing, but here is goes: (this is pseudo-code, I think is enough to get you started, I'll provide real-code if you so wish) when inserting, construct an hash to map between item data and the item index my $data = 0; # this needs to be unique! my %map; foreach ( ... things to insert ... ) { my $item = INSERT_ITEM; # this provides at least 2 * 10^9 unique data identifiers, # should be enough $list->SetItemData( $item, ++$data ); $map{$data} = $item; } When sorting, use the hash to map from the data to the index: sub callback { my( $f, $s ) = @_; my( $i1, $i2 ) = ( $map{$f}, $map{$s} ); # now you can use $i1, $i2 to retrieve the labels # and compare them } HTH Mattia |