[EMAIL PROTECTED] wrote:
> Hi.. I have a problem with the listbox widget. There doesn't
> appear to be a way to tell when the first item of a listbox
> is selected because it's index is 0. But in perl 0 also means
> undefined

completely wrong! :-)
0 does not mean undefined, there is a small but significant
difference between the two. consult the perldata manpage,
under the section: Scalar values.

>           and if nothing is selected SelectedItems returns
> undefined ie: 0 so there's no way to tell whether the first
> item is selected or not. :( Can anyone think of a hack to
> get around this?

the 'hack' is provided by the defined() function.
you can check first if there is any selected item with this
instructions:

    if(defined( $listbox->SelectedItems() )) {
        @items = $listbox->SelectedItems();
    } else {
        # nothing is selected
    }

BTW, if nothing is selected the function does not return 0.
try this code:
    
    @items = $listbox->SelectedItems();
    print "SelectedItems: ", join(", ", @items), "\n";

if nothing is selected, it will print:
    SelectedItems:
if the first item is selected, it will print:
    SelectedItems: 0

    
cheers,
Aldo

__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;



Reply via email to