Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Listbox keeping the selection in 1 listbox

by renegadex (Beadle)
on Jul 12, 2008 at 10:57 UTC ( [id://697196]=perlquestion: print w/replies, xml ) Need Help??

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

i want to make a listbox keep it's selection on a particular item. Example, i have the following listbox item: index - value 0 - "APPLE" 1 - "BANANA" 2 - "CARROTS" I want to move CARROTS above BANANA, so what I did is get the index of CARROTS and APPLE, then deleted CARROTS and inserted a new CARROTS. but the selection on the CARROTS is lost. I have to click on it again for it to be selected. How do i keep the selection on CARROTS??
  • Comment on Listbox keeping the selection in 1 listbox

Replies are listed 'Best First'.
Re: Listbox keeping the selection in 1 listbox
by psini (Deacon) on Jul 12, 2008 at 11:16 UTC

    It is no more the same carrot so you can't expect the listbox to "keep" the selection on "it".

    You have to save somewhere the selection before changing the list contents and then restore it. How to do it is depending on what identifies an item being "the same" after the change. In the example you give, I would save the value (not the index) of the selected item(s) and the select again the items holding the same values.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      but how do i select that new item? i have tried to use $canvas->activate(1) but it doesn't highlight the item.. nothing seems to be working.. haaay...

        I never used Tk::Listbox so this is little more than a guess but, based on a cursory read of POD, I think that the methods you need are listbox->activate($index) that makes the element of index $index the current element and listbox->selectionSet($index,$index) that put the element $index in the selection set.

        Obviously you need to know the index of the element you want to activate, so you'll probably have to search for it in the listbox itself.

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re: Listbox keeping the selection in 1 listbox
by zentara (Archbishop) on Jul 12, 2008 at 13:40 UTC
    use $listbox->SelectionSet($index) where $index is the new position for CARROTS. By the way, $canvas->activate(1) dosn't make sense unless you named your listbox as $canvas.

    I'm not really a human, but I play one on earth CandyGram for Mongo
      haha i did'nt saw that i wrote canvas instead of listbox. my mistake. thanks for the answer! i was having a hard time understanding the selectionset method. :) thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://697196]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found