Re: Set selection item for listbox
- From: "Gerald W. Lester" <Gerald.Lester@xxxxxxx>
- Date: Wed, 31 Jan 2007 08:23:13 -0600
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|
+------------------------------------------------------------------------+
.
- Follow-Ups:
- Re: Set selection item for listbox
- From: Kevin Walzer
- Re: Set selection item for listbox
- References:
- Set selection item for listbox
- From: Kevin Walzer
- Set selection item for listbox
- Prev by Date: Re: Tcl bytecode
- Next by Date: Re: Set selection item for listbox
- Previous by thread: Set selection item for listbox
- Next by thread: Re: Set selection item for listbox
- Index(es):