Roode, Eric wrote:
AH!  The light dawns!  The problem is not in the Listbox, it's in my
expectations of it.  :-)

I had thought that a multi-column listbox would show multiple sub-items
*per selectable item*, sort of the way a ListView works.

Say I was doing library books, and the user's search returns four
possibilities.  I want them to choose from one of the four, but I want
to show them multiple bits of information about each.  Say, title, card
number, and shelf location:

    +---------------------------------------------+-+
    |  Green Eggs and Ham    JF SEU   Children's  |^|
    |  A Brief History of..  897.112  2nd Floor   |#|
    |  Kim                   F KIPL   Attic       |#|
    |  Your Book Title Here  501.2    Vault       |v|
    +---------------------------------------------+-+

I'd like the user to click on any one of those, have the whole line be
highlighted, and have an event trigger so I could fetch the requested
information.

Is this possible?  Should I be (ab)using a ListView for this?

A ListView is exactly what you want.  No abuse involved.

#!perl -w
use strict;
use warnings;

use Win32::GUI();

my $mw = Win32::GUI::Window->new(
    -title => "ListView - Report Mode",
    -size  => [400,300],
);

$mw->AddListView(
    -name   => "LV",
    -width  => $mw->ScaleWidth(),
    -height => $mw->ScaleHeight(),
    -report => 1,
    -fullrowselect => 1,
    -onItemClick   => \&itemSelected,
);

for my $col_name ("Title", "Card Number", "Shelf Location") {
    $mw->LV->InsertColumn(
        -text  => $col_name,
        -width => 100,
    );
}

$mw->LV->InsertItem(
    -text => [ "Green Eggs and Ham", "JF SEU", "Children's", ],
);
$mw->LV->InsertItem(
-text => [ "A Brief History of the Universe", "897.112", "2nd Floor", ],
);
$mw->LV->InsertItem(
    -text => [ "Your Book Title Here", "501.2", "Vault", ],
);

$mw->Show();
Win32::GUI::Dialog();
exit(0);

sub itemSelected {
    my ($self, $item) = @_;

    my %info = $self->GetItem($item);

    print qq(Selected: "$info{-text}"\n);

    return 1;
}
__END__

Reply via email to