From: Mattia B. <mb...@ds...> - 2002-04-22 20:37:24
|
> On Sun, 21 Apr 2002, Mattia Barbon wrote: > > > You forgot platform & wxPerl version, so I won't give you the solution ;-p > > > > Win32, ActivePerl 5.6.1 build 628, wxPerl 0.09 -- sorry for not including > before. My guess was almost right :-) > > I see; this: the problem is that GetItemData takes the index of the item > > $list->GetItemData( $ebent->GetIndex() ), or $event->GetData() works fine > > > > Yes, you can use the long as an index in an array ( or in an hash ) containing > > the hashrefs, though. > > > > Ok, so I should have a hash keyed on the long and then have the value for > that key be a hashref? Yes, exactly > Could you provide some sample code, please? I would really appreciate it. > I'm confused that the $id in my original code is always 0. I would really > appreciate some sample code here. note that I didn't test it, but it should work ( or at leats give the idea ) # this should be in $object, but this is just an example... my @entries; # Add items to list foreach (@{$object->{tree}->GetPlData($event->GetItem())}) { my $id = $object->{list}->InsertStringItem(0, $_->{name}); my %fileDetails = ( name => $_->{name}, abspath => $_->{abspath}, volume => $_->{volume} ); # remember to update @entries when you add/remove items # from the list push @entries, \%fileDetails; my $index = scalar(@entries) - 1; $object->{list}->SetItemData($id, $index); $object->{list}->SetItem($id, 1, $_->{duration}); $object->{list}->SetItem($id, 2, $_->{title}); $object->{list}->SetItem($id, 3, $_->{artist}); $object->{list}->SetItem($id, 4, $_->{album}); $object->{list}->SetItem($id, 5, $_->{bitrate}); $object->{list}->SetItem($id, 6, (sprintf "%.2f", ($_->{size} / 1000000)) . ' MB'); } sub OnActivate { my($this, $event) = @_; my $index = $event->GetData(); # or $list->GetItemData($event->GetIndex()); my $data = $entries[$index]; #... } HTH Mattia |