Wx::ListBox->SetSelection(wxNOT_FOUND) does not work on Windows
(Strawberry Perl)

Hi

Sample code with two listboxes to show the difference in behaviour.
Works on Linux, selects all items on Windows XP.
I'm using perl 5.10, wxperl 0.89 via CPAN in both cases.

Cheers
Karl
---------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;

use Wx;

package ListBoxSelection;
use Wx qw[:everything];
use base 'Wx::App';
use Wx::Event qw(EVT_LISTBOX);

my $listbox1;
my $listbox2;

sub OnInit
{
    my $self = shift;
   
    my $frame = Wx::Frame->new( undef, -1, 'Wx::ListBox selection example');
    my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
   
    $listbox1 = Wx::ListBox->new($frame, -1, wxDefaultPosition,
wxDefaultSize,
        [ 'This', 'is one of my', 'really', 'wonderful', 'examples', ],
        wxLB_EXTENDED, wxDefaultValidator, 'listbox_1');
       
    $listbox2 = Wx::ListBox->new($frame, -1, wxDefaultPosition,
wxDefaultSize,
        [ 1, 2, 3, 4, 5],
        wxLB_EXTENDED, wxDefaultValidator, 'listbox_2');
       
    EVT_LISTBOX($self, $listbox1, sub { $self->on_listbox($listbox1,
$_[1]) } );
    EVT_LISTBOX($self, $listbox2, sub { $self->on_listbox($listbox2,
$_[1]) } );

    $sizer->Add($listbox1, 1, wxEXPAND, 10);
    $sizer->Add($listbox2, 1, wxEXPAND, 10);
    $frame->SetSizerAndFit($sizer);
    $frame->Show( 1 );   
}

sub on_listbox
{
    my $self = shift;
    my $ctrl = shift;
    my $event = shift;

    print "-------------------------\n";
    my @choices = $ctrl->GetSelections();

    print "status-in  :\n";
    print "1: " . join (', ', $listbox1->GetSelections()) . "\n";
    print "2: " . join (', ', $listbox2->GetSelections()) . "\n";

    map { $listbox1->Deselect($_); } [0, 1, 2, 3, 4];
    $listbox2->SetSelection(wxNOT_FOUND);

    foreach my $choice (@choices)
    {
        $listbox1->Select($choice);
        $listbox2->Select($choice);
    }

    print "status-out  :\n";
    print "1: " . join (', ', $listbox1->GetSelections()) . "\n";
    print "2: " . join (', ', $listbox2->GetSelections()) . "\n";
}


package main;

my $app = ListBoxSelection->new;
$app->MainLoop;


Reply via email to