Re: Set selection item for listbox



Kevin Walzer wrote:
I want to search a listbox for a term and set the selection to that term:

listbox .l -listvariable foo
pack .l

set foo "John"

set listitem [list John Paul George Ringo]

foreach item $listitem {
.l insert end $item
}

.l selection set [lindex [lsearch -inline [.l get 0 end] "John"]]

This code returns this error:

Error in startup script: bad listbox index "John": must be active,
anchor, end, @x,y, or a number
while executing
".l selection set [lindex [lsearch -inline [.l get 0 end] "John"]]"

Can anyone point me in the right direction?


Try executing the following commands interactively and see if you see what is wrong:
% set listitem [list John Paul George Ringo]
% lsearch -inline $listitem "John"
% lindex John


That is for starters. Looking at your code, I think you should reread the listbox, lindex and lsearch man/help pages.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.