Book HomeMastering Perl/TkSearch this book

7.9. Retrieving Elements

The get method returns a list of Listbox elements specified by the indexes firstindex to lastindex:

$lb->get(firstindex [,  lastindex ]);

If only the firstindex is specified, only one element is returned. The firstindex must be less than or equal to the lastindex. To get a list of all elements in the Listbox:

@elements = $lb->get(0, 'end');

To get the last item in the Listbox:

$lastitem = $lb->get('end');

To find out which items in the Listbox are selected, use the curselection method:

@list = $lb->curselection();

It returns a list containing the indexes of all currently selected items in the Listbox. If no items are selected, curselection returns an empty string. Here is an example of how the curselection method is used:

@selected = $lb->curselection;
foreach (@selected) {
  # do something with the index in $_
}

Remember that curselection returns a list of indexes, not elements.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.