On 19/09/2007, Brian Rowlands (Greymouth High School)
<[EMAIL PROTECTED]> wrote:
> I've used TheLoft to create a gui interface for a program I'm writing. A
> button I click is meant to read a selected line from a listview pane and
> display the results in a selection of tf / cb controls:
>
>     # determine which rows have been selected
>     my @selection = $win-> lvwFleece-> SelectedItems();
>
> 1. @selection contains the index values of the rows selected. However,
> if no rows are selected I was expecting it to be return a () array but
> printing its size in such a case shows a value of 1. Why would that be?

Bug, in my opinion.  There is similar behaviour throughout the XS code
where the return value from subs that are expected to return lists is
incorrect for there being no values - the subs return undef rather
than the empty list.

You'll find the one item in the list is undef.

I'm fixing them as I find them, despite the change being non-backwards
compatible, as it's very useful to be able to write:

# process all selected items
for ($win->SelectedItems()) {
    process_item($_);
}

rather than what you have to do now:

# process all selected items
for ($win->SelectedItems()) {
    next if not defined $_;
    process_item($_);
}

or some equivalent.  So long as code handles both empty lists and the
undefined value case, then there is no backwards-compatibility issue.
Backwards compatibility issues may occur with any code that assumes
the list has at least one entry and check the first value in the list
for definedness.



> 2. I really need some better way to determine if the listview has been
> clicked. The event ItemClick(ITEM) in the package description for
> listview looks as though it could be a better option for me. Can
> someone kindly help me to construct the line to determine if the
> listview has had a line selected please? I'm still learning perl and
> I'm puzzled how to do this simple task.

Does this help?

#!perl -w
use strict;
use warnings;

use Win32::GUI qw();

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,
    -singlesel   => 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__

Regards,
Rob.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to