From: Nick J. <sk...@er...> - 2002-04-21 14:52:58
|
I have got a wxPerl application that contains a Wx::TreeCtrl and a Wx::ListCtrl. Whenever a Wx::TreeCtrl item is activated, new items are inserted in the list control. The "items" are stored as data in the tree control. I am attempting to supply a hashref as data for each item in the list control. So, in my EVT_TREE_SEL_CHANGED callback function I have the following code: # 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} ); $object->{list}->SetItemData($id, \%fileDetails); $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'); } Adding the actual *items* works fine (they display properly in the list). The only problem is that setting the item data simply *does not work*. Bizarrely, whenever I print out $id in the above function, it is *always* zero. Anyway in my EVT_LIST_ITEM_ACTIVATED callback function I have: my $file_details = $object->{list}->GetItemData($event->GetItem()); but this causes a message box to appear saying: "Cannot retrieve information for list control item XXXXXXXX" (i.e. it includes the item number). I think the problem is that there is no SetPlData etc. for listctrl like there is for treectrl. The C++ documentation seems to show that a listctrl item can only have a 'long' associated with it. How can I associate a hashref with each item in a listctrl and how I can access this hashref when the item is "activated"? Thanks, Nick |