michaelg has asked for the wisdom of the Perl Monks concerning the following question:

@selected = $tl->curselection; foreach (@selected) { # Do something with the index: $selitem = $tl->get($_); }

I did this but I think that curselection and get don't work with the TList I know that instead curselection I can do : $tl->info('selection'). But what I can do instead $tl->get Using $tl->get give me an Error message

Thanks,

janitored by ybiC: <code> tags around example code, as per Monastery convetion

Replies are listed 'Best First'.
Re: Tlist get selected
by jeffa (Bishop) on Sep 07, 2003 at 14:55 UTC
    I know that you can get a list of the selected item(s) like so:
    my @index = $tlist->info('selection');
    But i have no idea how to get, say, the text of that/those particular item(s). There is no get() method for Tk::TList and none of the other available methods in the docs are looking good. I am starting to believe that you are not suppose to need to have a handle on the selected object ... hopefully someone will come along soon and prove this wrong. (and hopefully someone will finally write some decent docs for Tk!)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Once upon a time, I wrote the following ($l is a Tk::TList, Scrolled)
      sub KosherINC { my $l = shift; @INC = (); if( $l->index('end') ) { # index ain't documented (grr) for(0 .. $l->index('end') ) { push @INC, $l->entrycget($_ => '-text'); } } }
      What it does is push onto @INC all the entries in the list. Isn't Tk wonderful? {grin}

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        Hello PodMaster! You are the great .$tl->entrycget($index->'-text') is work pretty well. Everybody who are looking for this ,use this and thanks to PodMaster Thanks,
Re: Tlist get selected
by graff (Chancellor) on Sep 07, 2003 at 22:03 UTC
    I read through the manpage on the TList widget, and learned the following:
    • In order to know how to correctly extract content from the (set of) selected item(s), you have to know what sort of data they contain -- that is, what sort of data you put into the selected item(s): image, text, or "imagetext".
    • The only features that set TList apart from a common, simple Listbox are: (1) the ability to assign distinct colors to individual list items (all items in a Listbox use the same colors), and (2) the ability to have items shown in a grid, with the indexing ordered horizontally or vertically (Listbox only displays a single-column vertical list).

    If you don't happen to be using either of those two special features, then you might as well stick with using a plain old Listbox -- it's easier. If you do need those features, then Podmaster's sub-reply, together with your own knowledge about how you are putting items into the TList, should lead you to the answer.